1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2024-12-14 00:48:44 +01:00
dxvk/src/util/util_env.cpp

62 lines
1.5 KiB
C++
Raw Normal View History

2017-12-08 11:18:23 +01:00
#include "util_env.h"
#include <vector>
2017-12-08 11:18:23 +01:00
#include "./com/com_include.h"
namespace dxvk::env {
std::string getEnvVar(const std::string& name) {
int nameLen = ::MultiByteToWideChar(CP_ACP, 0, name.c_str(), name.length() + 1, nullptr, 0);
std::vector<WCHAR> wideName(nameLen);
::MultiByteToWideChar(CP_ACP, 0, name.c_str(), name.length() + 1, wideName.data(), nameLen);
DWORD len = ::GetEnvironmentVariableW(wideName.data(), nullptr, 0);
2017-12-08 11:18:23 +01:00
std::vector<WCHAR> result;
2017-12-08 11:18:23 +01:00
while (len > result.size()) {
result.resize(len);
len = ::GetEnvironmentVariableW(
wideName.data(), result.data(), result.size());
2017-12-08 11:18:23 +01:00
}
result.resize(len);
return str::fromws(result.data());
2017-12-08 11:18:23 +01:00
}
std::string getExeName() {
std::vector<WCHAR> exePath;
exePath.resize(MAX_PATH + 1);
DWORD len = ::GetModuleFileNameW(NULL, exePath.data(), MAX_PATH);
exePath.resize(len);
std::string fullPath = str::fromws(exePath.data());
auto n = fullPath.find_last_of('\\');
return (n != std::string::npos)
? fullPath.substr(n + 1)
: fullPath;
}
void setThreadName(const wchar_t* name) {
using SetThreadDescriptionProc = void (WINAPI *) (HANDLE, PCWSTR);
HMODULE module = ::GetModuleHandleW(L"kernel32.dll");
if (module == nullptr)
return;
auto proc = reinterpret_cast<SetThreadDescriptionProc>(
::GetProcAddress(module, "SetThreadDescription"));
if (proc != nullptr)
(*proc)(::GetCurrentThread(), name);
}
2017-12-08 11:18:23 +01:00
}