diff --git a/src/util/util_env.cpp b/src/util/util_env.cpp index 528d1d2e4..c4a02477c 100644 --- a/src/util/util_env.cpp +++ b/src/util/util_env.cpp @@ -16,7 +16,7 @@ namespace dxvk::env { } result.resize(len); - return str::fromws(result); + return str::fromws(result.data()); } @@ -27,7 +27,7 @@ namespace dxvk::env { DWORD len = ::GetModuleFileNameW(NULL, &exePath.at(0), MAX_PATH); exePath.resize(len); - std::string fullPath = str::fromws(exePath); + std::string fullPath = str::fromws(exePath.data()); auto n = fullPath.find_last_of('\\'); return (n != std::string::npos) @@ -52,3 +52,23 @@ namespace dxvk::env { } } + +#ifdef CP_UNIXCP +static constexpr int cp = CP_UNIXCP; +#else +static constexpr int cp = CP_ACP; +#endif + +namespace dxvk::str { + std::string fromws(const WCHAR *ws) { + size_t len = WideCharToMultiByte(cp, 0, ws, -1, NULL, 0, NULL, NULL); + if (len <= 1) + return ""; + + len--; + std::string result; + result.resize(len); + WideCharToMultiByte(cp, 0, ws, -1, &result.at(0), len, NULL, NULL); + return result; + } +} diff --git a/src/util/util_string.h b/src/util/util_string.h index 9704c5289..191c462d1 100644 --- a/src/util/util_string.h +++ b/src/util/util_string.h @@ -1,9 +1,8 @@ #pragma once -#include -#include #include #include +#include namespace dxvk::str { @@ -22,8 +21,6 @@ namespace dxvk::str { return stream.str(); } - inline std::string fromws(const std::wstring& ws) { - return std::wstring_convert>().to_bytes(ws); - } + std::string fromws(const WCHAR *ws); }