2017-12-08 11:18:23 +01:00
|
|
|
#include "util_env.h"
|
|
|
|
|
|
|
|
#include "./com/com_include.h"
|
|
|
|
|
|
|
|
namespace dxvk::env {
|
|
|
|
|
2019-01-13 21:27:59 +01:00
|
|
|
std::string getEnvVar(const char* name) {
|
|
|
|
char* result = std::getenv(name);
|
|
|
|
return (result)
|
|
|
|
? result
|
|
|
|
: "";
|
2017-12-08 11:18:23 +01:00
|
|
|
}
|
|
|
|
|
2018-01-16 11:33:34 +01:00
|
|
|
|
|
|
|
std::string getExeName() {
|
2019-08-17 11:46:40 +02:00
|
|
|
std::string fullPath = getExePath();
|
2018-01-16 11:33:34 +01:00
|
|
|
auto n = fullPath.find_last_of('\\');
|
|
|
|
|
|
|
|
return (n != std::string::npos)
|
|
|
|
? fullPath.substr(n + 1)
|
|
|
|
: fullPath;
|
|
|
|
}
|
2019-08-17 11:46:40 +02:00
|
|
|
|
|
|
|
|
|
|
|
std::string getExePath() {
|
|
|
|
std::vector<WCHAR> exePath;
|
|
|
|
exePath.resize(MAX_PATH + 1);
|
|
|
|
|
|
|
|
DWORD len = ::GetModuleFileNameW(NULL, exePath.data(), MAX_PATH);
|
|
|
|
exePath.resize(len);
|
|
|
|
|
|
|
|
return str::fromws(exePath.data());
|
|
|
|
}
|
2018-01-16 11:33:34 +01:00
|
|
|
|
2018-03-21 02:45:11 +01:00
|
|
|
|
2019-01-11 13:43:15 +01:00
|
|
|
void setThreadName(const std::string& name) {
|
2019-06-19 18:35:42 +02:00
|
|
|
using SetThreadDescriptionProc = HRESULT (WINAPI *) (HANDLE, PCWSTR);
|
2018-06-21 15:12:04 +02:00
|
|
|
|
2019-09-22 10:11:17 +02:00
|
|
|
static auto proc = reinterpret_cast<SetThreadDescriptionProc>(
|
|
|
|
::GetProcAddress(::GetModuleHandleW(L"kernel32.dll"), "SetThreadDescription"));
|
2018-06-21 15:12:04 +02:00
|
|
|
|
2019-02-11 21:36:23 +01:00
|
|
|
if (proc != nullptr) {
|
|
|
|
auto wideName = str::tows(name);
|
2019-01-11 13:43:15 +01:00
|
|
|
(*proc)(::GetCurrentThread(), wideName.data());
|
2019-02-11 21:36:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool createDirectory(const std::string& path) {
|
|
|
|
auto widePath = str::tows(path);
|
|
|
|
return !!CreateDirectoryW(widePath.data(), nullptr);
|
2018-06-21 15:12:04 +02:00
|
|
|
}
|
2018-03-21 02:45:11 +01:00
|
|
|
|
2017-12-08 11:18:23 +01:00
|
|
|
}
|