2017-12-08 11:18:23 +01:00
|
|
|
#include "util_env.h"
|
2018-07-18 02:01:24 +02:00
|
|
|
#include <vector>
|
2017-12-08 11:18:23 +01:00
|
|
|
|
|
|
|
#include "./com/com_include.h"
|
|
|
|
|
|
|
|
namespace dxvk::env {
|
|
|
|
|
|
|
|
std::string getEnvVar(const wchar_t* name) {
|
|
|
|
DWORD len = ::GetEnvironmentVariableW(name, nullptr, 0);
|
|
|
|
|
2018-07-18 02:01:24 +02:00
|
|
|
std::vector<WCHAR> result;
|
2017-12-08 11:18:23 +01:00
|
|
|
|
|
|
|
while (len > result.size()) {
|
|
|
|
result.resize(len);
|
|
|
|
len = ::GetEnvironmentVariableW(
|
2018-07-18 02:01:24 +02:00
|
|
|
name, result.data(), result.size());
|
2017-12-08 11:18:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
result.resize(len);
|
2018-07-18 01:49:30 +02:00
|
|
|
return str::fromws(result.data());
|
2017-12-08 11:18:23 +01:00
|
|
|
}
|
|
|
|
|
2018-01-16 11:33:34 +01:00
|
|
|
|
|
|
|
std::string getExeName() {
|
2018-07-18 02:01:24 +02:00
|
|
|
std::vector<WCHAR> exePath;
|
2018-01-16 11:33:34 +01:00
|
|
|
exePath.resize(MAX_PATH + 1);
|
|
|
|
|
2018-07-18 02:01:24 +02:00
|
|
|
DWORD len = ::GetModuleFileNameW(NULL, exePath.data(), MAX_PATH);
|
2018-01-16 11:33:34 +01:00
|
|
|
exePath.resize(len);
|
|
|
|
|
2018-07-18 01:49:30 +02:00
|
|
|
std::string fullPath = str::fromws(exePath.data());
|
2018-01-16 11:33:34 +01:00
|
|
|
auto n = fullPath.find_last_of('\\');
|
|
|
|
|
|
|
|
return (n != std::string::npos)
|
|
|
|
? fullPath.substr(n + 1)
|
|
|
|
: fullPath;
|
|
|
|
}
|
|
|
|
|
2018-03-21 02:45:11 +01:00
|
|
|
|
2018-06-21 15:12:04 +02:00
|
|
|
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);
|
|
|
|
}
|
2018-03-21 02:45:11 +01:00
|
|
|
|
2017-12-08 11:18:23 +01:00
|
|
|
}
|