#include #include "util_env.h" namespace dxvk::env { #ifndef DXVK_NATIVE constexpr char dirSlash = '\\'; #else constexpr char dirSlash = '/'; #endif std::string getEnvVar(const char* name) { #ifdef DXVK_NATIVE char* result = std::getenv(name); return (result) ? result : ""; #else std::vector result; result.resize(MAX_PATH + 1); DWORD len = ::GetEnvironmentVariableW(str::tows(name).c_str(), result.data(), MAX_PATH); result.resize(len); return str::fromws(result.data()); #endif } size_t matchFileExtension(const std::string& name, const char* ext) { auto pos = name.find_last_of('.'); if (pos == std::string::npos) return pos; bool matches = std::accumulate(name.begin() + pos + 1, name.end(), true, [&ext] (bool current, char a) { if (a >= 'A' && a <= 'Z') a += 'a' - 'A'; return current && *ext && a == *(ext++); }); return matches ? pos : std::string::npos; } std::string getExeName() { std::string fullPath = getExePath(); auto n = fullPath.find_last_of(dirSlash); return (n != std::string::npos) ? fullPath.substr(n + 1) : fullPath; } std::string getExeBaseName() { auto exeName = getExeName(); #ifndef DXVK_NATIVE auto extp = matchFileExtension(exeName, "exe"); if (extp != std::string::npos) exeName.erase(extp); #endif return exeName; } }