30 std::array<char, 128> buffer;
33 std::string fullCmd = cmd +
" 2>&1";
34 FILE* pipe = popen(fullCmd.c_str(),
"r");
42 constexpr size_t kMaxOutput = 1u * 1024 * 1024;
43 while (fgets(buffer.data(),
static_cast<int>(buffer.size()), pipe) !=
nullptr)
45 result += buffer.data();
46 if (result.size() > kMaxOutput)
50 int status = pclose(pipe);
56 *exitCode = WIFEXITED(status) ? WEXITSTATUS(status) : -1;
66 result.erase(result.find_last_not_of(
" \n\r\t") + 1);
73 return std::filesystem::exists(path, ec);
76std::string
trim(
const std::string& str)
78 size_t first = str.find_first_not_of(
" \t\n\r");
79 if (first == std::string::npos)
81 size_t last = str.find_last_not_of(
" \t\n\r");
82 return str.substr(first, (last - first + 1));
104 return "Configuring";
125 return "Redistributables";
178 [](
const std::shared_ptr<std::future<void>>& fu)
180 return fu->wait_for(std::chrono::seconds(0)) ==
181 std::future_status::ready;
190 initializeDependencyDatabase();
196 impl_->cancelRequested.store(
true);
200 std::vector<std::shared_ptr<std::future<void>>> pending;
202 std::lock_guard<std::mutex> lock(impl_->futuresMutex);
203 pending = std::move(impl_->activeFutures);
205 for (
auto& f : pending)
220 return !findExecutable(
"winetricks").empty();
225 return !findExecutable(
"protontricks").empty();
233 std::string output = executeCommand(
"winetricks --version");
242 std::string output = executeCommand(
"protontricks --version");
252 std::lock_guard<std::mutex> lock(impl_->mutex);
253 return impl_->dependencies;
256std::vector<WineDependency>
259 std::lock_guard<std::mutex> lock(impl_->mutex);
260 std::vector<WineDependency> result;
261 for (
const auto& dep : impl_->dependencies)
263 if (dep.category == category)
265 result.push_back(dep);
271std::optional<WineDependency>
274 std::lock_guard<std::mutex> lock(impl_->mutex);
275 for (
const auto& dep : impl_->dependencies)
277 if (dep.id == verbId)
282 for (
const auto& alias : dep.aliases)
293std::vector<WineDependency>
296 std::lock_guard<std::mutex> lock(impl_->mutex);
297 std::vector<WineDependency> result;
299 std::string lowerQuery = query;
300 std::transform(lowerQuery.begin(), lowerQuery.end(), lowerQuery.begin(),
301 [](
unsigned char c) { return static_cast<char>(::tolower(c)); });
303 for (
const auto& dep : impl_->dependencies)
305 std::string lowerId = dep.id;
306 std::string lowerName = dep.name;
307 std::string lowerDesc = dep.description;
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)); });
316 if (lowerId.find(lowerQuery) != std::string::npos ||
317 lowerName.find(lowerQuery) != std::string::npos ||
318 lowerDesc.find(lowerQuery) != std::string::npos)
320 result.push_back(dep);
348 status.
lastScanned = std::chrono::system_clock::now();
353 if (
const std::filesystem::path syswow64 = prefixPath /
"drive_c" /
"windows" /
"syswow64";
354 fileExists(syswow64))
368 for (
const auto& rec : recommended)
373 if (installed == rec)
389 const std::string& verbId)
const
391 auto installed = parseInstalledFromLog(prefixPath);
392 for (
const auto& verb : installed)
401 if (verbId ==
"vcrun2019" || verbId ==
"vcrun2022")
403 std::filesystem::path vcruntime =
404 prefixPath /
"drive_c" /
"windows" /
"system32" /
"vcruntime140.dll";
405 return fileExists(vcruntime);
408 if (verbId ==
"dotnet48")
410 std::filesystem::path ndpPath =
411 prefixPath /
"drive_c" /
"windows" /
"Microsoft.NET" /
"Framework" /
"v4.0.30319";
412 return fileExists(ndpPath);
418std::vector<std::string>
420 const std::vector<std::string>& requiredVerbs)
const
422 std::vector<std::string> missing;
423 for (
const auto& verb : requiredVerbs)
427 missing.push_back(verb);
438 const std::string& verbId,
441 impl_->cancelRequested =
false;
445 if (progressCallback)
450 progressCallback(progress);
455 return runWinetricks(prefixPath, {verbId}, progressCallback);
460 const std::string& verbId,
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]()
475 promise->set_value(ok);
479 promise->set_exception(std::current_exception());
482 impl_->storeFuture(std::move(workerFuture));
487 const std::vector<std::string>& verbIds,
490 impl_->cancelRequested =
false;
491 int successCount = 0;
494 progress.
verbsTotal =
static_cast<int>(verbIds.size());
496 for (
size_t i = 0; i < verbIds.size(); ++i)
498 if (impl_->cancelRequested)
501 if (progressCallback)
502 progressCallback(progress);
508 progress.
percentComplete =
static_cast<int>(((i + 1) * 100) / verbIds.size());
510 if (progressCallback)
511 progressCallback(progress);
513 if (runWinetricks(prefixPath, {verbIds[i]},
nullptr))
521 if (impl_->cancelRequested)
529 if (progressCallback)
530 progressCallback(progress);
536 const std::vector<std::string>& verbIds,
539 impl_->cancelRequested =
false;
543 if (progressCallback)
547 progress.
errorMessage =
"protontricks is not installed";
548 progressCallback(progress);
553 return runProtontricks(steamAppId, verbIds, progressCallback);
560std::vector<DLLOverride>
563 std::vector<DLLOverride> overrides;
566 std::filesystem::path userReg = prefixPath /
"user.reg";
567 if (!fileExists(userReg))
572 std::ifstream file(userReg);
574 bool inDllOverrides =
false;
576 while (std::getline(file, line))
578 if (line.find(
"[Software\\\\Wine\\\\DllOverrides]") != std::string::npos)
580 inDllOverrides =
true;
586 if (line.empty() || line[0] ==
'[')
592 std::regex dllRegex(
"\"([^\"]+)\"=\"([^\"]+)\"");
594 if (std::regex_search(line, match, dllRegex))
597 override.
dllName = match[1].str();
598 override.mode = match[2].str();
599 override.isActive =
true;
600 overrides.push_back(
override);
609 const std::string& dllName,
const std::string& mode)
618 static const std::string kDllOverridesKey =
"HKEY_CURRENT_USER\\Software\\Wine\\DllOverrides";
626 executeCommand(cmd, &exitCode);
627 return exitCode == 0;
631 const std::string& dllName)
633 static const std::string kDllOverridesKey =
"HKEY_CURRENT_USER\\Software\\Wine\\DllOverrides";
640 executeCommand(cmd, &exitCode);
641 return exitCode == 0;
651 std::vector<std::string> verbs = {
"vcrun2019",
"dxvk",
"corefonts"};
653 static_cast<int>(verbs.size());
659 std::vector<std::string> verbs = {
"d3dx9",
"d3dx10",
"d3dx11_43",
"d3dcompiler_43",
662 static_cast<int>(verbs.size());
666 const std::string& version,
669 std::string verb =
"dotnet" + version;
679 std::lock_guard<std::mutex> lock(impl_->mutex);
680 impl_->winePath = winePath;
685 std::lock_guard<std::mutex> lock(impl_->mutex);
686 impl_->winetricksPath = path;
691 impl_->guiMode = enabled;
696 impl_->cancelRequested =
true;
709 executeCommand(
"winetricks --self-update", &exitCode);
710 return exitCode == 0;
716 if (fileExists(cacheDir))
719 std::filesystem::remove_all(cacheDir, ec);
725 const char* home = std::getenv(
"HOME");
728 return std::filesystem::path(home) /
".cache" /
"winetricks";
737bool WineDependencyManager::runWinetricks(
const std::filesystem::path& prefixPath,
738 const std::vector<std::string>& args,
739 const ProgressCallback& callback)
747 std::filesystem::path winePathSnapshot;
748 std::filesystem::path winetricksPathSnapshot;
749 bool guiModeSnapshot;
751 std::lock_guard<std::mutex> lock(impl_->mutex);
752 winePathSnapshot = impl_->winePath;
753 winetricksPathSnapshot = impl_->winetricksPath;
754 guiModeSnapshot = impl_->guiMode;
757 std::string winetricks = winetricksPathSnapshot.empty() ? std::string(
"winetricks")
758 : winetricksPathSnapshot.string();
763 if (!winePathSnapshot.empty())
771 if (!guiModeSnapshot)
773 cmd +=
" --unattended";
777 for (
const auto& arg : args)
784 DependencyInstallProgress progress;
786 progress.
currentVerb = args.empty() ?
"" : args[0];
798 DependencyInstallProgress progress;
806 progress.
errorMessage =
"winetricks failed with exit code " + std::to_string(exitCode);
811 return exitCode == 0;
814bool WineDependencyManager::runProtontricks(uint32_t appId,
const std::vector<std::string>& args,
815 const ProgressCallback& callback)
817 std::string cmd =
"protontricks --no-background-wineserver ";
818 cmd += std::to_string(appId);
820 for (
const auto& arg : args)
827 DependencyInstallProgress progress;
829 progress.
currentVerb = args.empty() ?
"" : args[0];
841 DependencyInstallProgress progress;
850 "protontricks failed with exit code " + std::to_string(exitCode);
855 return exitCode == 0;
858void WineDependencyManager::initializeDependencyDatabase()
860 std::lock_guard<std::mutex> lock(impl_->mutex);
863 impl_->dependencies.push_back({
"vcrun2005",
865 "Microsoft Visual C++ 2005 Redistributable",
877 impl_->dependencies.push_back({
"vcrun2008",
879 "Microsoft Visual C++ 2008 Redistributable",
891 impl_->dependencies.push_back({
"vcrun2010",
893 "Microsoft Visual C++ 2010 Redistributable",
905 impl_->dependencies.push_back({
"vcrun2012",
907 "Microsoft Visual C++ 2012 Redistributable",
919 impl_->dependencies.push_back({
"vcrun2013",
921 "Microsoft Visual C++ 2013 Redistributable",
933 impl_->dependencies.push_back({
"vcrun2015",
935 "Microsoft Visual C++ 2015 Redistributable",
947 impl_->dependencies.push_back({
"vcrun2017",
949 "Microsoft Visual C++ 2017 Redistributable",
961 impl_->dependencies.push_back({
"vcrun2019",
963 "Microsoft Visual C++ 2015-2019 Redistributable",
975 impl_->dependencies.push_back({
"vcrun2022",
977 "Microsoft Visual C++ 2015-2022 Redistributable",
990 impl_->dependencies.push_back({
"dotnet35",
991 ".NET Framework 3.5",
992 "Microsoft .NET Framework 3.5",
1004 impl_->dependencies.push_back({
"dotnet40",
1005 ".NET Framework 4.0",
1006 "Microsoft .NET Framework 4.0",
1018 impl_->dependencies.push_back({
"dotnet45",
1019 ".NET Framework 4.5",
1020 "Microsoft .NET Framework 4.5",
1032 impl_->dependencies.push_back({
"dotnet46",
1033 ".NET Framework 4.6",
1034 "Microsoft .NET Framework 4.6",
1046 impl_->dependencies.push_back({
"dotnet48",
1047 ".NET Framework 4.8",
1048 "Microsoft .NET Framework 4.8",
1061 impl_->dependencies.push_back({
"d3dx9",
1063 "Microsoft DirectX 9 (d3dx9_26-43)",
1075 impl_->dependencies.push_back({
"d3dx10",
1077 "Microsoft DirectX 10",
1089 impl_->dependencies.push_back({
"d3dx11_43",
1091 "Microsoft DirectX 11 d3dx11_43",
1103 impl_->dependencies.push_back({
"d3dcompiler_43",
1105 "Microsoft DirectX D3D Compiler 43",
1117 impl_->dependencies.push_back({
"d3dcompiler_47",
1119 "Microsoft DirectX D3D Compiler 47",
1131 impl_->dependencies.push_back({
"dxvk",
1133 "Vulkan-based implementation of D3D9, D3D10, D3D11",
1145 impl_->dependencies.push_back({
"vkd3d",
1147 "Vulkan-based implementation of D3D12",
1160 impl_->dependencies.push_back({
"corefonts",
1162 "Microsoft Core TrueType Fonts",
1174 impl_->dependencies.push_back({
"tahoma",
1176 "Microsoft Tahoma font",
1188 impl_->dependencies.push_back({
"liberation",
1190 "Red Hat Liberation fonts",
1202 impl_->dependencies.push_back({
"allfonts",
1204 "All available fonts (cjkfonts, corefonts, etc.)",
1217 impl_->dependencies.push_back({
"physx",
1231 impl_->dependencies.push_back({
"xact",
1233 "Microsoft XACT (X3DAudio, XAudio, XAPOFX)",
1245 impl_->dependencies.push_back({
"xinput",
1247 "Microsoft XInput (Xbox controller support)",
1259 impl_->dependencies.push_back({
"xna31",
1261 "Microsoft XNA Framework 3.1",
1273 impl_->dependencies.push_back({
"xna40",
1275 "Microsoft XNA Framework 4.0",
1287 impl_->dependencies.push_back({
"faudio",
1289 "FAudio (XAudio reimplementation)",
1302 impl_->dependencies.push_back({
"win10",
1304 "Set Windows version to Windows 10",
1316 impl_->dependencies.push_back({
"win7",
1318 "Set Windows version to Windows 7",
1330 impl_->dependencies.push_back({
"winxp",
1332 "Set Windows version to Windows XP",
1344 impl_->dependencies.push_back({
"renderer=vulkan",
1346 "Set Wine renderer to Vulkan",
1358 impl_->dependencies.push_back({
"renderer=gl",
1360 "Set Wine renderer to OpenGL",
1372 impl_->dependencies.push_back({
"csmt=on",
1374 "Enable Command Stream Multi-Threading",
1387std::vector<std::string>
1388WineDependencyManager::parseInstalledFromLog(
const std::filesystem::path& prefixPath)
const
1390 std::vector<std::string> installed;
1393 std::filesystem::path logPath = prefixPath /
"winetricks.log";
1399 std::ifstream file(logPath);
1401 while (std::getline(file, line))
1404 if (!line.empty() && line[0] !=
'#')
1406 installed.push_back(line);
static std::string escapeArg(const std::string &arg)
Escape a string for safe use as a shell argument.
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)
std::string findExecutable(const std::string &name)
std::string trim(const std::string &str)
DLL override configuration.
Progress information during dependency installation.
std::string getStateStr() const
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::filesystem::path winetricksPath
std::vector< std::shared_ptr< std::future< void > > > activeFutures
void storeFuture(std::shared_ptr< std::future< void > > f)
std::atomic< bool > cancelRequested
std::filesystem::path winePath
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.