forked from doitsujin/dxvk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil_env.cpp
61 lines (40 loc) · 1.51 KB
/
util_env.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "util_env.h"
#include <vector>
#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);
std::vector<WCHAR> result;
while (len > result.size()) {
result.resize(len);
len = ::GetEnvironmentVariableW(
wideName.data(), result.data(), result.size());
}
result.resize(len);
return str::fromws(result.data());
}
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);
}
}