diff --git a/src/util/util_env.cpp b/src/util/util_env.cpp new file mode 100644 index 00000000..4da507e3 --- /dev/null +++ b/src/util/util_env.cpp @@ -0,0 +1,22 @@ +#include "util_env.h" + +#include "./com/com_include.h" + +namespace dxvk::env { + + std::string getEnvVar(const wchar_t* name) { + DWORD len = ::GetEnvironmentVariableW(name, nullptr, 0); + + std::wstring result; + + while (len > result.size()) { + result.resize(len); + len = ::GetEnvironmentVariableW( + name, result.data(), result.size()); + } + + result.resize(len); + return str::fromws(result); + } + +} diff --git a/src/util/util_env.h b/src/util/util_env.h new file mode 100644 index 00000000..ad9cdf52 --- /dev/null +++ b/src/util/util_env.h @@ -0,0 +1,18 @@ +#pragma once + +#include "util_string.h" + +namespace dxvk::env { + + /** + * \brief Gets environment variable + * + * If the variable is not defined, this will return + * an empty string. Note that environment variables + * may be defined with an empty value. + * \param [in] name Name of the variable + * \returns Value of the variable + */ + std::string getEnvVar(const wchar_t* name); + +} \ No newline at end of file