game_launcher 1.1.0
Modern Linux game launcher with Steam / Proton / Wine integration
Loading...
Searching...
No Matches
wine_dependency_manager.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// ==============================================================================
3// wine_dependency_manager.cpp
4// ==============================================================================
5// Wine dependency and component installation manager implementation
6// ==============================================================================
7
9#include "util/shell_utils.h"
10
11#include <algorithm>
12#include <array>
13#include <cstdlib>
14#include <fstream>
15#include <future>
16#include <memory>
17#include <mutex>
18#include <regex>
19#include <utility>
20
21// ==============================================================================
22// Helper Functions
23// ==============================================================================
24
25namespace
26{
27
28std::string executeCommand(const std::string& cmd, int* exitCode = nullptr)
29{
30 std::array<char, 128> buffer;
31 std::string result;
32
33 std::string fullCmd = cmd + " 2>&1";
34 FILE* pipe = popen(fullCmd.c_str(), "r");
35 if (!pipe)
36 {
37 if (exitCode)
38 *exitCode = -1;
39 return "";
40 }
41
42 constexpr size_t kMaxOutput = 1u * 1024 * 1024; // 1 MB
43 while (fgets(buffer.data(), static_cast<int>(buffer.size()), pipe) != nullptr)
44 {
45 result += buffer.data();
46 if (result.size() > kMaxOutput)
47 break;
48 }
49
50 int status = pclose(pipe);
51 if (exitCode)
52 {
53 if (status == -1)
54 *exitCode = -1;
55 else
56 *exitCode = WIFEXITED(status) ? WEXITSTATUS(status) : -1;
57 }
58
59 return result;
60}
61
62std::string findExecutable(const std::string& name)
63{
64 std::string result = executeCommand("which " + ShellUtils::escapeArg(name));
65 // Trim whitespace
66 result.erase(result.find_last_not_of(" \n\r\t") + 1);
67 return result;
68}
69
70bool fileExists(const std::filesystem::path& path)
71{
72 std::error_code ec;
73 return std::filesystem::exists(path, ec);
74}
75
76std::string trim(const std::string& str)
77{
78 size_t first = str.find_first_not_of(" \t\n\r");
79 if (first == std::string::npos)
80 return "";
81 size_t last = str.find_last_not_of(" \t\n\r");
82 return str.substr(first, (last - first + 1));
83}
84
85} // namespace
86
87// ==============================================================================
88// DependencyInstallProgress Methods
89// ==============================================================================
90
92{
93 switch (state)
94 {
95 case State::Starting:
96 return "Starting";
98 return "Downloading";
100 return "Extracting";
102 return "Installing";
104 return "Configuring";
105 case State::Completed:
106 return "Completed";
107 case State::Failed:
108 return "Failed";
109 case State::Cancelled:
110 return "Cancelled";
111 default:
112 return "Unknown";
113 }
114}
115
116// ==============================================================================
117// Category Name Helper
118// ==============================================================================
119
121{
122 switch (category)
123 {
125 return "Redistributables";
127 return "DirectX";
129 return "Fonts";
131 return "Libraries";
133 return "Settings";
135 return "Game Fixes";
137 return "Other";
138 default:
139 return "Unknown";
140 }
141}
142
143// ==============================================================================
144// WineDependencyManager Implementation
145// ==============================================================================
146
148{
149 std::filesystem::path winePath;
150 std::filesystem::path winetricksPath;
151 bool guiMode = false;
152 std::atomic<bool> cancelRequested{false};
153 mutable std::mutex mutex;
154
155 // Dependency database
156 std::vector<WineDependency> dependencies;
157
158 // Async-worker tracking. installDependencyAsync captures `this`; if the
159 // caller drops the returned future without waiting, the worker keeps
160 // running and would UAF on `impl_` once the destructor runs. We track
161 // each worker's `future<void>` here so the destructor can join them.
162 // Separate mutex so a worker re-entering via setWinePath/setWinetricksPath
163 // (which take `mutex`) cannot deadlock with the destructor's join.
164 std::mutex futuresMutex;
165 std::vector<std::shared_ptr<std::future<void>>> activeFutures;
166
168 {
169 // Auto-detect paths
170 winetricksPath = findExecutable("winetricks");
171 winePath = findExecutable("wine");
172 }
173
174 void storeFuture(std::shared_ptr<std::future<void>> f)
175 {
176 std::lock_guard<std::mutex> lock(futuresMutex);
177 activeFutures.erase(std::remove_if(activeFutures.begin(), activeFutures.end(),
178 [](const std::shared_ptr<std::future<void>>& fu)
179 {
180 return fu->wait_for(std::chrono::seconds(0)) ==
181 std::future_status::ready;
182 }),
183 activeFutures.end());
184 activeFutures.push_back(std::move(f));
185 }
186};
187
189{
190 initializeDependencyDatabase();
191}
192
194{
195 // 1. Cooperative cancel so any cancellable worker short-circuits.
196 impl_->cancelRequested.store(true);
197 // 2. Wait for every outstanding async worker before `impl_` goes away.
198 // Move the vector out under the lock; releasing the mutex before
199 // waiting avoids any chance of deadlock with a worker callback.
200 std::vector<std::shared_ptr<std::future<void>>> pending;
201 {
202 std::lock_guard<std::mutex> lock(impl_->futuresMutex);
203 pending = std::move(impl_->activeFutures);
204 }
205 for (auto& f : pending)
206 {
207 if (f && f->valid())
208 {
209 f->wait();
210 }
211 }
212}
213
214// ==============================================================================
215// Availability Check
216// ==============================================================================
217
219{
220 return !findExecutable("winetricks").empty();
221}
222
224{
225 return !findExecutable("protontricks").empty();
226}
227
229{
231 return "";
232
233 std::string output = executeCommand("winetricks --version");
234 return trim(output);
235}
236
238{
240 return "";
241
242 std::string output = executeCommand("protontricks --version");
243 return trim(output);
244}
245
246// ==============================================================================
247// Dependency Information
248// ==============================================================================
249
250std::vector<WineDependency> WineDependencyManager::getAllDependencies() const
251{
252 std::lock_guard<std::mutex> lock(impl_->mutex);
253 return impl_->dependencies;
254}
255
256std::vector<WineDependency>
258{
259 std::lock_guard<std::mutex> lock(impl_->mutex);
260 std::vector<WineDependency> result;
261 for (const auto& dep : impl_->dependencies)
262 {
263 if (dep.category == category)
264 {
265 result.push_back(dep);
266 }
267 }
268 return result;
269}
270
271std::optional<WineDependency>
272WineDependencyManager::getDependencyInfo(const std::string& verbId) const
273{
274 std::lock_guard<std::mutex> lock(impl_->mutex);
275 for (const auto& dep : impl_->dependencies)
276 {
277 if (dep.id == verbId)
278 {
279 return dep;
280 }
281 // Check aliases
282 for (const auto& alias : dep.aliases)
283 {
284 if (alias == verbId)
285 {
286 return dep;
287 }
288 }
289 }
290 return std::nullopt;
291}
292
293std::vector<WineDependency>
294WineDependencyManager::searchDependencies(const std::string& query) const
295{
296 std::lock_guard<std::mutex> lock(impl_->mutex);
297 std::vector<WineDependency> result;
298
299 std::string lowerQuery = query;
300 std::transform(lowerQuery.begin(), lowerQuery.end(), lowerQuery.begin(),
301 [](unsigned char c) { return static_cast<char>(::tolower(c)); });
302
303 for (const auto& dep : impl_->dependencies)
304 {
305 std::string lowerId = dep.id;
306 std::string lowerName = dep.name;
307 std::string lowerDesc = dep.description;
308
309 std::transform(lowerId.begin(), lowerId.end(), lowerId.begin(),
310 [](unsigned char c) { return static_cast<char>(::tolower(c)); });
311 std::transform(lowerName.begin(), lowerName.end(), lowerName.begin(),
312 [](unsigned char c) { return static_cast<char>(::tolower(c)); });
313 std::transform(lowerDesc.begin(), lowerDesc.end(), lowerDesc.begin(),
314 [](unsigned char c) { return static_cast<char>(::tolower(c)); });
315
316 if (lowerId.find(lowerQuery) != std::string::npos ||
317 lowerName.find(lowerQuery) != std::string::npos ||
318 lowerDesc.find(lowerQuery) != std::string::npos)
319 {
320 result.push_back(dep);
321 }
322 }
323
324 return result;
325}
326
328{
329 return {
330 "vcrun2019", // Visual C++ 2015-2019 Redistributable
331 "vcrun2022", // Visual C++ 2015-2022 Redistributable
332 "dxvk", // Vulkan-based D3D9/10/11 implementation
333 "vkd3d", // Vulkan-based D3D12 implementation
334 "corefonts", // Microsoft core fonts
335 "d3dcompiler_47", // DirectX shader compiler
336 };
337}
338
339// ==============================================================================
340// Prefix Analysis
341// ==============================================================================
342
344WineDependencyManager::scanPrefix(const std::filesystem::path& prefixPath) const
345{
347 status.prefixPath = prefixPath;
348 status.lastScanned = std::chrono::system_clock::now();
349
350 // Determine architecture by probing for the syswow64 directory; its
351 // presence implies a 64-bit prefix (that path holds the 32-bit
352 // bitness compat libs on win64).
353 if (const std::filesystem::path syswow64 = prefixPath / "drive_c" / "windows" / "syswow64";
354 fileExists(syswow64))
355 {
356 status.architecture = "win64";
357 }
358 else
359 {
360 status.architecture = "win32";
361 }
362
363 // Parse installed verbs from winetricks log
364 status.installedVerbs = parseInstalledFromLog(prefixPath);
365
366 // Check for missing recommended
367 auto recommended = getRecommendedDependencies();
368 for (const auto& rec : recommended)
369 {
370 bool found = false;
371 for (const auto& installed : status.installedVerbs)
372 {
373 if (installed == rec)
374 {
375 found = true;
376 break;
377 }
378 }
379 if (!found)
380 {
381 status.missingRecommended.push_back(rec);
382 }
383 }
384
385 return status;
386}
387
388bool WineDependencyManager::isDependencyInstalled(const std::filesystem::path& prefixPath,
389 const std::string& verbId) const
390{
391 auto installed = parseInstalledFromLog(prefixPath);
392 for (const auto& verb : installed)
393 {
394 if (verb == verbId)
395 {
396 return true;
397 }
398 }
399
400 // Also check for common DLLs/files associated with verbs
401 if (verbId == "vcrun2019" || verbId == "vcrun2022")
402 {
403 std::filesystem::path vcruntime =
404 prefixPath / "drive_c" / "windows" / "system32" / "vcruntime140.dll";
405 return fileExists(vcruntime);
406 }
407
408 if (verbId == "dotnet48")
409 {
410 std::filesystem::path ndpPath =
411 prefixPath / "drive_c" / "windows" / "Microsoft.NET" / "Framework" / "v4.0.30319";
412 return fileExists(ndpPath);
413 }
414
415 return false;
416}
417
418std::vector<std::string>
419WineDependencyManager::getMissingDependencies(const std::filesystem::path& prefixPath,
420 const std::vector<std::string>& requiredVerbs) const
421{
422 std::vector<std::string> missing;
423 for (const auto& verb : requiredVerbs)
424 {
425 if (!isDependencyInstalled(prefixPath, verb))
426 {
427 missing.push_back(verb);
428 }
429 }
430 return missing;
431}
432
433// ==============================================================================
434// Installation
435// ==============================================================================
436
437bool WineDependencyManager::installDependency(const std::filesystem::path& prefixPath,
438 const std::string& verbId,
439 const ProgressCallback& progressCallback)
440{
441 impl_->cancelRequested = false;
442
444 {
445 if (progressCallback)
446 {
449 progress.errorMessage = "winetricks is not installed";
450 progressCallback(progress);
451 }
452 return false;
453 }
454
455 return runWinetricks(prefixPath, {verbId}, progressCallback);
456}
457
458std::future<bool>
459WineDependencyManager::installDependencyAsync(const std::filesystem::path& prefixPath,
460 const std::string& verbId,
461 const ProgressCallback& progressCallback)
462{
463 // Split the worker-side future from the caller-side future so that a
464 // caller who drops the returned future does NOT strand the worker (the
465 // worker captures `this`, so its lifetime must be bounded by ours).
466 auto promise = std::make_shared<std::promise<bool>>();
467 auto callerFuture = promise->get_future();
468 auto workerFuture = std::make_shared<std::future<void>>(
469 std::async(std::launch::async,
470 [this, prefixPath, verbId, progressCallback, promise]()
471 {
472 try
473 {
474 bool ok = installDependency(prefixPath, verbId, progressCallback);
475 promise->set_value(ok);
476 }
477 catch (...)
478 {
479 promise->set_exception(std::current_exception());
480 }
481 }));
482 impl_->storeFuture(std::move(workerFuture));
483 return callerFuture;
484}
485
486int WineDependencyManager::installDependencies(const std::filesystem::path& prefixPath,
487 const std::vector<std::string>& verbIds,
488 const ProgressCallback& progressCallback)
489{
490 impl_->cancelRequested = false;
491 int successCount = 0;
492
494 progress.verbsTotal = static_cast<int>(verbIds.size());
495
496 for (size_t i = 0; i < verbIds.size(); ++i)
497 {
498 if (impl_->cancelRequested)
499 {
501 if (progressCallback)
502 progressCallback(progress);
503 break;
504 }
505
506 progress.currentVerb = verbIds[i];
507 progress.verbsCompleted = static_cast<int>(i + 1);
508 progress.percentComplete = static_cast<int>(((i + 1) * 100) / verbIds.size());
509
510 if (progressCallback)
511 progressCallback(progress);
512
513 if (runWinetricks(prefixPath, {verbIds[i]}, nullptr))
514 {
515 successCount++;
516 }
517 }
518
519 // If the loop broke out on cancellation it already emitted the Cancelled
520 // progress callback; do not overwrite it with a bogus "Completed / 100%".
521 if (impl_->cancelRequested)
522 {
523 return successCount;
524 }
525
527 progress.verbsCompleted = static_cast<int>(verbIds.size());
528 progress.percentComplete = 100;
529 if (progressCallback)
530 progressCallback(progress);
531
532 return successCount;
533}
534
536 const std::vector<std::string>& verbIds,
537 const ProgressCallback& progressCallback)
538{
539 impl_->cancelRequested = false;
540
542 {
543 if (progressCallback)
544 {
547 progress.errorMessage = "protontricks is not installed";
548 progressCallback(progress);
549 }
550 return false;
551 }
552
553 return runProtontricks(steamAppId, verbIds, progressCallback);
554}
555
556// ==============================================================================
557// DLL Override Management
558// ==============================================================================
559
560std::vector<DLLOverride>
561WineDependencyManager::getDLLOverrides(const std::filesystem::path& prefixPath) const
562{
563 std::vector<DLLOverride> overrides;
564
565 // Read from user.reg
566 std::filesystem::path userReg = prefixPath / "user.reg";
567 if (!fileExists(userReg))
568 {
569 return overrides;
570 }
571
572 std::ifstream file(userReg);
573 std::string line;
574 bool inDllOverrides = false;
575
576 while (std::getline(file, line))
577 {
578 if (line.find("[Software\\\\Wine\\\\DllOverrides]") != std::string::npos)
579 {
580 inDllOverrides = true;
581 continue;
582 }
583
584 if (inDllOverrides)
585 {
586 if (line.empty() || line[0] == '[')
587 {
588 break; // End of section
589 }
590
591 // Parse "dllname"="mode"
592 std::regex dllRegex("\"([^\"]+)\"=\"([^\"]+)\"");
593 std::smatch match;
594 if (std::regex_search(line, match, dllRegex))
595 {
596 DLLOverride override;
597 override.dllName = match[1].str();
598 override.mode = match[2].str();
599 override.isActive = true;
600 overrides.push_back(override);
601 }
602 }
603 }
604
605 return overrides;
606}
607
608bool WineDependencyManager::setDLLOverride(const std::filesystem::path& prefixPath,
609 const std::string& dllName, const std::string& mode)
610{
612 return false;
613
614 // Use wine reg to set the override.
615 // The registry-path literal is constant today, but consistency (every
616 // token shell-escaped through escapeArg) prevents a future "make path
617 // configurable" change from silently regressing into shell injection.
618 static const std::string kDllOverridesKey = "HKEY_CURRENT_USER\\Software\\Wine\\DllOverrides";
619
620 std::string cmd = "WINEPREFIX=" + ShellUtils::escapeArg(prefixPath.string()) + " ";
621 cmd += "wine reg add " + ShellUtils::escapeArg(kDllOverridesKey) + " ";
622 cmd += "/v " + ShellUtils::escapeArg(dllName) + " /t REG_SZ /d " + ShellUtils::escapeArg(mode) +
623 " /f";
624
625 int exitCode = 0;
626 executeCommand(cmd, &exitCode);
627 return exitCode == 0;
628}
629
630bool WineDependencyManager::removeDLLOverride(const std::filesystem::path& prefixPath,
631 const std::string& dllName)
632{
633 static const std::string kDllOverridesKey = "HKEY_CURRENT_USER\\Software\\Wine\\DllOverrides";
634
635 std::string cmd = "WINEPREFIX=" + ShellUtils::escapeArg(prefixPath.string()) + " ";
636 cmd += "wine reg delete " + ShellUtils::escapeArg(kDllOverridesKey) + " ";
637 cmd += "/v " + ShellUtils::escapeArg(dllName) + " /f";
638
639 int exitCode = 0;
640 executeCommand(cmd, &exitCode);
641 return exitCode == 0;
642}
643
644// ==============================================================================
645// Quick Install Presets
646// ==============================================================================
647
648bool WineDependencyManager::installGamingPreset(const std::filesystem::path& prefixPath,
649 const ProgressCallback& progressCallback)
650{
651 std::vector<std::string> verbs = {"vcrun2019", "dxvk", "corefonts"};
652 return installDependencies(prefixPath, verbs, progressCallback) ==
653 static_cast<int>(verbs.size());
654}
655
656bool WineDependencyManager::installDirectXPreset(const std::filesystem::path& prefixPath,
657 const ProgressCallback& progressCallback)
658{
659 std::vector<std::string> verbs = {"d3dx9", "d3dx10", "d3dx11_43", "d3dcompiler_43",
660 "d3dcompiler_47"};
661 return installDependencies(prefixPath, verbs, progressCallback) ==
662 static_cast<int>(verbs.size());
663}
664
665bool WineDependencyManager::installDotNet(const std::filesystem::path& prefixPath,
666 const std::string& version,
667 const ProgressCallback& progressCallback)
668{
669 std::string verb = "dotnet" + version;
670 return installDependency(prefixPath, verb, progressCallback);
671}
672
673// ==============================================================================
674// Configuration
675// ==============================================================================
676
677void WineDependencyManager::setWinePath(const std::filesystem::path& winePath)
678{
679 std::lock_guard<std::mutex> lock(impl_->mutex);
680 impl_->winePath = winePath;
681}
682
683void WineDependencyManager::setWinetricksPath(const std::filesystem::path& path)
684{
685 std::lock_guard<std::mutex> lock(impl_->mutex);
686 impl_->winetricksPath = path;
687}
688
690{
691 impl_->guiMode = enabled;
692}
693
695{
696 impl_->cancelRequested = true;
697}
698
699// ==============================================================================
700// Utility
701// ==============================================================================
702
704{
706 return false;
707
708 int exitCode = 0;
709 executeCommand("winetricks --self-update", &exitCode);
710 return exitCode == 0;
711}
712
714{
715 auto cacheDir = getCacheDirectory();
716 if (fileExists(cacheDir))
717 {
718 std::error_code ec;
719 std::filesystem::remove_all(cacheDir, ec);
720 }
721}
722
723std::filesystem::path WineDependencyManager::getCacheDirectory() const
724{
725 const char* home = std::getenv("HOME");
726 if (home)
727 {
728 return std::filesystem::path(home) / ".cache" / "winetricks";
729 }
730 return {};
731}
732
733// ==============================================================================
734// Private Methods
735// ==============================================================================
736
737bool WineDependencyManager::runWinetricks(const std::filesystem::path& prefixPath,
738 const std::vector<std::string>& args,
739 const ProgressCallback& callback)
740{
741 // Snapshot the configured paths under the mutex. Reading
742 // `impl_->winetricksPath` / `impl_->winePath` directly here would be a
743 // data race against `setWinePath` / `setWinetricksPath`, both of which
744 // take `mutex` to write. `std::filesystem::path` is a class with an
745 // internal string buffer; concurrent read+write is UB per the C++
746 // memory model. Snapshot once, release the lock, then use locals.
747 std::filesystem::path winePathSnapshot;
748 std::filesystem::path winetricksPathSnapshot;
749 bool guiModeSnapshot;
750 {
751 std::lock_guard<std::mutex> lock(impl_->mutex);
752 winePathSnapshot = impl_->winePath;
753 winetricksPathSnapshot = impl_->winetricksPath;
754 guiModeSnapshot = impl_->guiMode;
755 }
756
757 std::string winetricks = winetricksPathSnapshot.empty() ? std::string("winetricks")
758 : winetricksPathSnapshot.string();
759
760 std::string cmd = "WINEPREFIX=" + ShellUtils::escapeArg(prefixPath.string()) + " ";
761
762 // Add wine path if specified
763 if (!winePathSnapshot.empty())
764 {
765 cmd += "WINE=" + ShellUtils::escapeArg(winePathSnapshot.string()) + " ";
766 }
767
768 cmd += ShellUtils::escapeArg(winetricks);
769
770 // Add flags
771 if (!guiModeSnapshot)
772 {
773 cmd += " --unattended";
774 }
775
776 // Add verbs
777 for (const auto& arg : args)
778 {
779 cmd += " " + ShellUtils::escapeArg(arg);
780 }
781
782 if (callback)
783 {
784 DependencyInstallProgress progress;
786 progress.currentVerb = args.empty() ? "" : args[0];
787 progress.currentStep = "Running winetricks...";
788 callback(progress);
789 }
790
791 int exitCode = 0;
792 // Output is intentionally discarded - the winetricks UI streams
793 // progress to its own console; we surface success via exitCode only.
794 (void)executeCommand(cmd, &exitCode);
795
796 if (callback)
797 {
798 DependencyInstallProgress progress;
799 if (exitCode == 0)
800 {
802 }
803 else
804 {
806 progress.errorMessage = "winetricks failed with exit code " + std::to_string(exitCode);
807 }
808 callback(progress);
809 }
810
811 return exitCode == 0;
812}
813
814bool WineDependencyManager::runProtontricks(uint32_t appId, const std::vector<std::string>& args,
815 const ProgressCallback& callback)
816{
817 std::string cmd = "protontricks --no-background-wineserver ";
818 cmd += std::to_string(appId);
819
820 for (const auto& arg : args)
821 {
822 cmd += " " + ShellUtils::escapeArg(arg);
823 }
824
825 if (callback)
826 {
827 DependencyInstallProgress progress;
829 progress.currentVerb = args.empty() ? "" : args[0];
830 progress.currentStep = "Running protontricks...";
831 callback(progress);
832 }
833
834 int exitCode = 0;
835 // Same rationale as runWinetricks above - exit code is the source of
836 // truth; stdout is consumed by protontricks's own progress UI.
837 (void)executeCommand(cmd, &exitCode);
838
839 if (callback)
840 {
841 DependencyInstallProgress progress;
842 if (exitCode == 0)
843 {
845 }
846 else
847 {
849 progress.errorMessage =
850 "protontricks failed with exit code " + std::to_string(exitCode);
851 }
852 callback(progress);
853 }
854
855 return exitCode == 0;
856}
857
858void WineDependencyManager::initializeDependencyDatabase()
859{
860 std::lock_guard<std::mutex> lock(impl_->mutex);
861
862 // Visual C++ Redistributables
863 impl_->dependencies.push_back({"vcrun2005",
864 "Visual C++ 2005",
865 "Microsoft Visual C++ 2005 Redistributable",
867 {"vc2005"},
868 false,
869 "",
870 {},
871 {},
872 false,
873 "",
874 0,
875 "Microsoft"});
876
877 impl_->dependencies.push_back({"vcrun2008",
878 "Visual C++ 2008",
879 "Microsoft Visual C++ 2008 Redistributable",
881 {"vc2008"},
882 false,
883 "",
884 {},
885 {},
886 false,
887 "",
888 0,
889 "Microsoft"});
890
891 impl_->dependencies.push_back({"vcrun2010",
892 "Visual C++ 2010",
893 "Microsoft Visual C++ 2010 Redistributable",
895 {"vc2010"},
896 false,
897 "",
898 {},
899 {},
900 false,
901 "",
902 0,
903 "Microsoft"});
904
905 impl_->dependencies.push_back({"vcrun2012",
906 "Visual C++ 2012",
907 "Microsoft Visual C++ 2012 Redistributable",
909 {"vc2012"},
910 false,
911 "",
912 {},
913 {},
914 false,
915 "",
916 0,
917 "Microsoft"});
918
919 impl_->dependencies.push_back({"vcrun2013",
920 "Visual C++ 2013",
921 "Microsoft Visual C++ 2013 Redistributable",
923 {"vc2013"},
924 false,
925 "",
926 {},
927 {},
928 false,
929 "",
930 0,
931 "Microsoft"});
932
933 impl_->dependencies.push_back({"vcrun2015",
934 "Visual C++ 2015",
935 "Microsoft Visual C++ 2015 Redistributable",
937 {"vc2015"},
938 false,
939 "",
940 {},
941 {},
942 false,
943 "",
944 0,
945 "Microsoft"});
946
947 impl_->dependencies.push_back({"vcrun2017",
948 "Visual C++ 2017",
949 "Microsoft Visual C++ 2017 Redistributable",
951 {"vc2017"},
952 false,
953 "",
954 {},
955 {},
956 false,
957 "",
958 0,
959 "Microsoft"});
960
961 impl_->dependencies.push_back({"vcrun2019",
962 "Visual C++ 2019",
963 "Microsoft Visual C++ 2015-2019 Redistributable",
965 {"vc2019"},
966 false,
967 "",
968 {},
969 {},
970 false,
971 "",
972 0,
973 "Microsoft"});
974
975 impl_->dependencies.push_back({"vcrun2022",
976 "Visual C++ 2022",
977 "Microsoft Visual C++ 2015-2022 Redistributable",
979 {"vc2022"},
980 false,
981 "",
982 {},
983 {},
984 false,
985 "",
986 0,
987 "Microsoft"});
988
989 // .NET Framework
990 impl_->dependencies.push_back({"dotnet35",
991 ".NET Framework 3.5",
992 "Microsoft .NET Framework 3.5",
994 {"dotnet35sp1"},
995 false,
996 "",
997 {},
998 {},
999 false,
1000 "",
1001 0,
1002 "Microsoft"});
1003
1004 impl_->dependencies.push_back({"dotnet40",
1005 ".NET Framework 4.0",
1006 "Microsoft .NET Framework 4.0",
1008 {},
1009 false,
1010 "",
1011 {},
1012 {},
1013 false,
1014 "",
1015 0,
1016 "Microsoft"});
1017
1018 impl_->dependencies.push_back({"dotnet45",
1019 ".NET Framework 4.5",
1020 "Microsoft .NET Framework 4.5",
1022 {},
1023 false,
1024 "",
1025 {"dotnet40"},
1026 {},
1027 false,
1028 "",
1029 0,
1030 "Microsoft"});
1031
1032 impl_->dependencies.push_back({"dotnet46",
1033 ".NET Framework 4.6",
1034 "Microsoft .NET Framework 4.6",
1036 {},
1037 false,
1038 "",
1039 {"dotnet45"},
1040 {},
1041 false,
1042 "",
1043 0,
1044 "Microsoft"});
1045
1046 impl_->dependencies.push_back({"dotnet48",
1047 ".NET Framework 4.8",
1048 "Microsoft .NET Framework 4.8",
1050 {},
1051 false,
1052 "",
1053 {},
1054 {},
1055 false,
1056 "",
1057 0,
1058 "Microsoft"});
1059
1060 // DirectX
1061 impl_->dependencies.push_back({"d3dx9",
1062 "DirectX 9",
1063 "Microsoft DirectX 9 (d3dx9_26-43)",
1065 {"directx9"},
1066 false,
1067 "",
1068 {},
1069 {},
1070 false,
1071 "",
1072 0,
1073 "Microsoft"});
1074
1075 impl_->dependencies.push_back({"d3dx10",
1076 "DirectX 10",
1077 "Microsoft DirectX 10",
1079 {},
1080 false,
1081 "",
1082 {},
1083 {},
1084 false,
1085 "",
1086 0,
1087 "Microsoft"});
1088
1089 impl_->dependencies.push_back({"d3dx11_43",
1090 "DirectX 11",
1091 "Microsoft DirectX 11 d3dx11_43",
1093 {},
1094 false,
1095 "",
1096 {},
1097 {},
1098 false,
1099 "",
1100 0,
1101 "Microsoft"});
1102
1103 impl_->dependencies.push_back({"d3dcompiler_43",
1104 "D3D Compiler 43",
1105 "Microsoft DirectX D3D Compiler 43",
1107 {},
1108 false,
1109 "",
1110 {},
1111 {},
1112 false,
1113 "",
1114 0,
1115 "Microsoft"});
1116
1117 impl_->dependencies.push_back({"d3dcompiler_47",
1118 "D3D Compiler 47",
1119 "Microsoft DirectX D3D Compiler 47",
1121 {},
1122 false,
1123 "",
1124 {},
1125 {},
1126 false,
1127 "",
1128 0,
1129 "Microsoft"});
1130
1131 impl_->dependencies.push_back({"dxvk",
1132 "DXVK",
1133 "Vulkan-based implementation of D3D9, D3D10, D3D11",
1135 {},
1136 false,
1137 "",
1138 {},
1139 {},
1140 false,
1141 "",
1142 0,
1143 "Community"});
1144
1145 impl_->dependencies.push_back({"vkd3d",
1146 "VKD3D",
1147 "Vulkan-based implementation of D3D12",
1149 {"vkd3d-proton"},
1150 false,
1151 "",
1152 {},
1153 {},
1154 true,
1155 "",
1156 0,
1157 "Community"});
1158
1159 // Fonts
1160 impl_->dependencies.push_back({"corefonts",
1161 "Core Fonts",
1162 "Microsoft Core TrueType Fonts",
1164 {},
1165 false,
1166 "",
1167 {},
1168 {},
1169 false,
1170 "",
1171 0,
1172 "Microsoft"});
1173
1174 impl_->dependencies.push_back({"tahoma",
1175 "Tahoma",
1176 "Microsoft Tahoma font",
1178 {},
1179 false,
1180 "",
1181 {},
1182 {},
1183 false,
1184 "",
1185 0,
1186 "Microsoft"});
1187
1188 impl_->dependencies.push_back({"liberation",
1189 "Liberation Fonts",
1190 "Red Hat Liberation fonts",
1192 {},
1193 false,
1194 "",
1195 {},
1196 {},
1197 false,
1198 "",
1199 0,
1200 "Red Hat"});
1201
1202 impl_->dependencies.push_back({"allfonts",
1203 "All Fonts",
1204 "All available fonts (cjkfonts, corefonts, etc.)",
1206 {},
1207 false,
1208 "",
1209 {},
1210 {},
1211 false,
1212 "",
1213 0,
1214 "Various"});
1215
1216 // Libraries
1217 impl_->dependencies.push_back({"physx",
1218 "PhysX",
1219 "NVIDIA PhysX",
1221 {},
1222 false,
1223 "",
1224 {},
1225 {},
1226 false,
1227 "",
1228 0,
1229 "NVIDIA"});
1230
1231 impl_->dependencies.push_back({"xact",
1232 "XACT",
1233 "Microsoft XACT (X3DAudio, XAudio, XAPOFX)",
1235 {"xact_x64"},
1236 false,
1237 "",
1238 {},
1239 {},
1240 false,
1241 "",
1242 0,
1243 "Microsoft"});
1244
1245 impl_->dependencies.push_back({"xinput",
1246 "XInput",
1247 "Microsoft XInput (Xbox controller support)",
1249 {},
1250 false,
1251 "",
1252 {},
1253 {},
1254 false,
1255 "",
1256 0,
1257 "Microsoft"});
1258
1259 impl_->dependencies.push_back({"xna31",
1260 "XNA 3.1",
1261 "Microsoft XNA Framework 3.1",
1263 {},
1264 false,
1265 "",
1266 {},
1267 {},
1268 false,
1269 "",
1270 0,
1271 "Microsoft"});
1272
1273 impl_->dependencies.push_back({"xna40",
1274 "XNA 4.0",
1275 "Microsoft XNA Framework 4.0",
1277 {},
1278 false,
1279 "",
1280 {},
1281 {},
1282 false,
1283 "",
1284 0,
1285 "Microsoft"});
1286
1287 impl_->dependencies.push_back({"faudio",
1288 "FAudio",
1289 "FAudio (XAudio reimplementation)",
1291 {},
1292 false,
1293 "",
1294 {},
1295 {},
1296 false,
1297 "",
1298 0,
1299 "Community"});
1300
1301 // Settings
1302 impl_->dependencies.push_back({"win10",
1303 "Windows 10 Mode",
1304 "Set Windows version to Windows 10",
1306 {"windows10"},
1307 false,
1308 "",
1309 {},
1310 {},
1311 false,
1312 "",
1313 0,
1314 ""});
1315
1316 impl_->dependencies.push_back({"win7",
1317 "Windows 7 Mode",
1318 "Set Windows version to Windows 7",
1320 {"windows7"},
1321 false,
1322 "",
1323 {},
1324 {},
1325 false,
1326 "",
1327 0,
1328 ""});
1329
1330 impl_->dependencies.push_back({"winxp",
1331 "Windows XP Mode",
1332 "Set Windows version to Windows XP",
1334 {"windowsxp"},
1335 false,
1336 "",
1337 {},
1338 {},
1339 false,
1340 "",
1341 0,
1342 ""});
1343
1344 impl_->dependencies.push_back({"renderer=vulkan",
1345 "Vulkan Renderer",
1346 "Set Wine renderer to Vulkan",
1348 {},
1349 false,
1350 "",
1351 {},
1352 {},
1353 false,
1354 "",
1355 0,
1356 ""});
1357
1358 impl_->dependencies.push_back({"renderer=gl",
1359 "OpenGL Renderer",
1360 "Set Wine renderer to OpenGL",
1362 {},
1363 false,
1364 "",
1365 {},
1366 {},
1367 false,
1368 "",
1369 0,
1370 ""});
1371
1372 impl_->dependencies.push_back({"csmt=on",
1373 "CSMT Enable",
1374 "Enable Command Stream Multi-Threading",
1376 {},
1377 false,
1378 "",
1379 {},
1380 {},
1381 false,
1382 "",
1383 0,
1384 ""});
1385}
1386
1387std::vector<std::string>
1388WineDependencyManager::parseInstalledFromLog(const std::filesystem::path& prefixPath) const
1389{
1390 std::vector<std::string> installed;
1391
1392 // Check winetricks.log
1393 std::filesystem::path logPath = prefixPath / "winetricks.log";
1394 if (!fileExists(logPath))
1395 {
1396 return installed;
1397 }
1398
1399 std::ifstream file(logPath);
1400 std::string line;
1401 while (std::getline(file, line))
1402 {
1403 line = trim(line);
1404 if (!line.empty() && line[0] != '#')
1405 {
1406 installed.push_back(line);
1407 }
1408 }
1409
1410 return installed;
1411}
static std::string escapeArg(const std::string &arg)
Escape a string for safe use as a shell argument.
Definition shell_utils.h:65
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.
bool fileExists(const std::filesystem::path &path)
std::string executeCommand(const std::string &cmd, int *exitCode=nullptr)
DLL override configuration.
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
std::vector< WineDependency > dependencies
std::vector< std::shared_ptr< std::future< void > > > activeFutures
void storeFuture(std::shared_ptr< std::future< void > > f)
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.
@ Game
Game-specific fixes.
@ Redistributable
VC++ redistributables, .NET, etc.