mirror of
https://github.com/doitsujin/dxvk.git
synced 2025-01-31 05:52:11 +01:00
[util] Reimplement fromws using WideCharToMultiByte and system codepage.
Also, using UTF-8 for convertion may not be what's intended, esp. if such strings end up being passed back to system API (eg. open file). The patch uses CP_ACP on mingw build (which is how Windows APIs will interpret it) or CP_UNIXCP on Wine (which is Wine extension to convert to whatever glibc and other host libs expect). It's also needed for the next patch.
This commit is contained in:
parent
02ae42c7de
commit
c2c10cc207
@ -16,7 +16,7 @@ namespace dxvk::env {
|
|||||||
}
|
}
|
||||||
|
|
||||||
result.resize(len);
|
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);
|
DWORD len = ::GetModuleFileNameW(NULL, &exePath.at(0), MAX_PATH);
|
||||||
exePath.resize(len);
|
exePath.resize(len);
|
||||||
|
|
||||||
std::string fullPath = str::fromws(exePath);
|
std::string fullPath = str::fromws(exePath.data());
|
||||||
auto n = fullPath.find_last_of('\\');
|
auto n = fullPath.find_last_of('\\');
|
||||||
|
|
||||||
return (n != std::string::npos)
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <locale>
|
|
||||||
#include <codecvt>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <windef.h>
|
||||||
|
|
||||||
namespace dxvk::str {
|
namespace dxvk::str {
|
||||||
|
|
||||||
@ -22,8 +21,6 @@ namespace dxvk::str {
|
|||||||
return stream.str();
|
return stream.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::string fromws(const std::wstring& ws) {
|
std::string fromws(const WCHAR *ws);
|
||||||
return std::wstring_convert<std::codecvt_utf8<wchar_t>>().to_bytes(ws);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user