From b899324b8c454261343fa5782961670732b61fa1 Mon Sep 17 00:00:00 2001 From: Rerence1016 Date: Sat, 2 Aug 2025 06:20:19 +0800 Subject: [PATCH] feat(exe): allow specifying games by their exe file --- src/utils/utils.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/utils/utils.cpp b/src/utils/utils.cpp index a83e80d..a264833 100644 --- a/src/utils/utils.cpp +++ b/src/utils/utils.cpp @@ -19,6 +19,7 @@ #include #include #include +#include using namespace Utils; @@ -233,6 +234,34 @@ std::pair Utils::getProcessName() { if (comm_str.back() == '\n') comm_str.pop_back(); + + // For .exe apps running through Proton/Wine + + std::ifstream cmdline_file("/proc/self/cmdline"); + if (!cmdline_file.is_open()) { + return {"", ""}; // Not sure what to do if it ISN'T open + } + std::string cmdline; + getline(cmdline_file, cmdline, '\0'); + + // If the process is a Proton/Wine app + if (cmdline.find(".exe") != std::string::npos) { + + // Extract just the executable name + std::regex pattern(R"([-\w\s\.()\[\]!@]*(\.[Ee][Xx][Ee]))"); + std::smatch match; + if (std::regex_search(cmdline, match, pattern)) { + comm_str = match[0]; + } + } else { + + // If it's not a .exe app, just use the comm string + + // Note: if not a Windows app, the name will still be + // cut off to just 15 characters as a limitation of + // using comm in /proc + } + return{ std::string(exe.data()), comm_str }; }