2017-12-08 11:18:23 +01:00
|
|
|
#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(
|
2018-01-15 13:08:23 +01:00
|
|
|
name, &result.at(0), result.size());
|
2017-12-08 11:18:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
result.resize(len);
|
|
|
|
return str::fromws(result);
|
|
|
|
}
|
|
|
|
|
2018-01-16 11:33:34 +01:00
|
|
|
|
|
|
|
std::string getExeName() {
|
|
|
|
std::wstring exePath;
|
|
|
|
exePath.resize(MAX_PATH + 1);
|
|
|
|
|
|
|
|
DWORD len = ::GetModuleFileNameW(NULL, &exePath.at(0), MAX_PATH);
|
|
|
|
exePath.resize(len);
|
|
|
|
|
|
|
|
std::string fullPath = str::fromws(exePath);
|
|
|
|
auto n = fullPath.find_last_of('\\');
|
|
|
|
|
|
|
|
return (n != std::string::npos)
|
|
|
|
? fullPath.substr(n + 1)
|
|
|
|
: fullPath;
|
|
|
|
}
|
|
|
|
|
2018-03-21 02:45:11 +01:00
|
|
|
|
|
|
|
std::string getTempDirectory() {
|
|
|
|
WCHAR windowsTempDir[MAX_PATH] = {0};
|
|
|
|
UINT ret = ::GetTempPathW(MAX_PATH, windowsTempDir);
|
|
|
|
if (ret > MAX_PATH || ret == 0)
|
|
|
|
return std::string();
|
|
|
|
|
|
|
|
auto dxvkTempDir = std::wstring(windowsTempDir) + L"dxvk\\";
|
|
|
|
if (::CreateDirectoryW(dxvkTempDir.c_str(), 0) == 0) {
|
|
|
|
if (::GetLastError() != ERROR_ALREADY_EXISTS)
|
|
|
|
return std::string();
|
|
|
|
}
|
|
|
|
|
|
|
|
return str::fromws(dxvkTempDir);
|
|
|
|
}
|
|
|
|
|
2017-12-08 11:18:23 +01:00
|
|
|
}
|