diff --git a/include/config/config.hpp b/include/config/config.hpp index 4aaeef9..f614e7c 100644 --- a/include/config/config.hpp +++ b/include/config/config.hpp @@ -2,7 +2,6 @@ #include -#include #include #include #include @@ -68,6 +67,6 @@ namespace Config { /// /// @throws std::runtime_error if the configuration is invalid. /// - Configuration getConfig(std::string_view name); + Configuration getConfig(const std::pair& name); } diff --git a/include/utils/utils.hpp b/include/utils/utils.hpp index 90185de..0dc8605 100644 --- a/include/utils/utils.hpp +++ b/include/utils/utils.hpp @@ -90,7 +90,7 @@ namespace Utils { /// /// @return The name of the process. /// - std::string getProcessName(); + std::pair getProcessName(); /// /// Get the configuration file path. diff --git a/src/context.cpp b/src/context.cpp index 080e6e8..ca16ff1 100644 --- a/src/context.cpp +++ b/src/context.cpp @@ -32,7 +32,7 @@ LsContext::LsContext(const Hooks::DeviceInfo& info, VkSwapchainKHR swapchain, // reread configuration const std::string file = Utils::getConfigFile(); - const std::string name = Utils::getProcessName(); + const auto name = Utils::getProcessName(); try { Config::updateConfig(file); conf = Config::getConfig(name); @@ -45,7 +45,7 @@ LsContext::LsContext(const Hooks::DeviceInfo& info, VkSwapchainKHR swapchain, LSFG_3_1::finalize(); // print config - std::cerr << "lsfg-vk: Reloaded configuration for " << name << ":\n"; + std::cerr << "lsfg-vk: Reloaded configuration for " << name.second << ":\n"; if (!conf.dll.empty()) std::cerr << " Using DLL from: " << conf.dll << '\n'; std::cerr << " Multiplier: " << conf.multiplier << '\n'; std::cerr << " Flow Scale: " << conf.flowScale << '\n'; diff --git a/src/extract/extract.cpp b/src/extract/extract.cpp index 108336a..35d1635 100644 --- a/src/extract/extract.cpp +++ b/src/extract/extract.cpp @@ -129,7 +129,7 @@ void Extract::extractShaders() { // ensure all shaders are present for (const auto& [name, idx] : nameIdxTable) if (shaders().find(idx) == shaders().end()) - throw std::runtime_error("Shader not found: " + name + ".\nIs Lossless Scaling up to date?"); + throw std::runtime_error("Shader not found: " + name + ".\n- Is Lossless Scaling up to date?"); } std::vector Extract::getShader(const std::string& name) { diff --git a/src/main.cpp b/src/main.cpp index bb2a0ad..de51b22 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -24,22 +24,22 @@ namespace { Utils::showErrorGui(e.what()); } - const std::string name = Utils::getProcessName(); + const auto name = Utils::getProcessName(); try { Config::activeConf = Config::getConfig(name); } catch (const std::exception& e) { - std::cerr << "lsfg-vk: The configuration for " << name << " is invalid, exiting:\n"; + std::cerr << "lsfg-vk: The configuration for " << name.second << " is invalid, exiting:\n"; std::cerr << e.what() << '\n'; Utils::showErrorGui(e.what()); } // exit silently if not enabled auto& conf = Config::activeConf; - if (!conf.enable && name != "benchmark") + if (!conf.enable && name.second != "benchmark") return; // print config - std::cerr << "lsfg-vk: Loaded configuration for " << name << ":\n"; + std::cerr << "lsfg-vk: Loaded configuration for " << name.second << ":\n"; if (!conf.dll.empty()) std::cerr << " Using DLL from: " << conf.dll << '\n'; for (const auto& [key, value] : conf.env) std::cerr << " Environment: " << key << "=" << value << '\n'; diff --git a/src/utils/gui.cpp b/src/utils/gui.cpp index 0f0dac5..a09c7cf 100644 --- a/src/utils/gui.cpp +++ b/src/utils/gui.cpp @@ -49,6 +49,8 @@ namespace { } void Utils::showErrorGui(const std::string& message) { + SetTraceLogLevel(LOG_WARNING); + const int height = DrawTextBox(message, 10, 60, 780, false); InitWindow(800, height + 80, "lsfg-vk - Error"); diff --git a/src/utils/utils.cpp b/src/utils/utils.cpp index f5205ee..33889ea 100644 --- a/src/utils/utils.cpp +++ b/src/utils/utils.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -208,16 +209,28 @@ void Utils::resetLimitN(const std::string& id) noexcept { } /// Get the process name -std::string Utils::getProcessName() { +std::pair Utils::getProcessName() { const char* benchmark_flag = std::getenv("LSFG_BENCHMARK"); if (benchmark_flag) - return "benchmark"; + return { "benchmark", "benchmark" }; std::array exe{}; + const ssize_t exe_len = readlink("/proc/self/exe", exe.data(), exe.size() - 1); if (exe_len <= 0) - return "Unknown Process"; + return { "Unknown Process", "unknown" }; exe.at(static_cast(exe_len)) = '\0'; - return{exe.data()}; + + std::ifstream comm_file("/proc/self/comm"); + if (!comm_file.is_open()) + return { std::string(exe.data()), "unknown" }; + std::array comm{}; + comm_file.read(comm.data(), 256); + comm.at(static_cast(comm_file.gcount())) = '\0'; + std::string comm_str(comm.data()); + if (comm_str.back() == '\n') + comm_str.pop_back(); + + return{ std::string(exe.data()), comm_str }; } /// Get the config file