mirror of
https://github.com/EduApps-CDG/OpenDX
synced 2024-12-30 09:45:37 +01:00
[util] Wide character conversion changes
Replaces tows with an easier helper that fits in nicer with fixed-size arrays in DXGI, etc. Prefer UTF8 in tows/fromws.
This commit is contained in:
parent
7e3142b2ed
commit
bf14371f9e
@ -223,8 +223,7 @@ namespace dxvk {
|
|||||||
|
|
||||||
// Convert device name
|
// Convert device name
|
||||||
std::memset(pDesc->Description, 0, sizeof(pDesc->Description));
|
std::memset(pDesc->Description, 0, sizeof(pDesc->Description));
|
||||||
::MultiByteToWideChar(CP_UTF8, 0, deviceProp.deviceName, -1,
|
str::tows(deviceProp.deviceName, pDesc->Description);
|
||||||
pDesc->Description, sizeof(pDesc->Description) / sizeof(*pDesc->Description));
|
|
||||||
|
|
||||||
// Get amount of video memory
|
// Get amount of video memory
|
||||||
// based on the Vulkan heaps
|
// based on the Vulkan heaps
|
||||||
|
@ -40,15 +40,17 @@ namespace dxvk::env {
|
|||||||
::GetProcAddress(::GetModuleHandleW(L"kernel32.dll"), "SetThreadDescription"));
|
::GetProcAddress(::GetModuleHandleW(L"kernel32.dll"), "SetThreadDescription"));
|
||||||
|
|
||||||
if (proc != nullptr) {
|
if (proc != nullptr) {
|
||||||
auto wideName = str::tows(name);
|
auto wideName = std::vector<WCHAR>(name.length() + 1);
|
||||||
|
str::tows(name.c_str(), wideName.data(), wideName.size());
|
||||||
(*proc)(::GetCurrentThread(), wideName.data());
|
(*proc)(::GetCurrentThread(), wideName.data());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool createDirectory(const std::string& path) {
|
bool createDirectory(const std::string& path) {
|
||||||
auto widePath = str::tows(path);
|
WCHAR widePath[MAX_PATH];
|
||||||
return !!CreateDirectoryW(widePath.data(), nullptr);
|
str::tows(path.c_str(), widePath);
|
||||||
|
return !!CreateDirectoryW(widePath, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,8 @@
|
|||||||
#include "util_string.h"
|
#include "util_string.h"
|
||||||
|
|
||||||
#ifdef CP_UNIXCP
|
|
||||||
static constexpr int cp = CP_UNIXCP;
|
|
||||||
#else
|
|
||||||
static constexpr int cp = CP_ACP;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace dxvk::str {
|
namespace dxvk::str {
|
||||||
std::string fromws(const WCHAR *ws) {
|
std::string fromws(const WCHAR *ws) {
|
||||||
size_t len = ::WideCharToMultiByte(cp,
|
size_t len = ::WideCharToMultiByte(CP_UTF8,
|
||||||
0, ws, -1, nullptr, 0, nullptr, nullptr);
|
0, ws, -1, nullptr, 0, nullptr, nullptr);
|
||||||
|
|
||||||
if (len <= 1)
|
if (len <= 1)
|
||||||
@ -18,24 +12,16 @@ namespace dxvk::str {
|
|||||||
|
|
||||||
std::string result;
|
std::string result;
|
||||||
result.resize(len);
|
result.resize(len);
|
||||||
::WideCharToMultiByte(cp, 0, ws, -1,
|
::WideCharToMultiByte(CP_UTF8, 0, ws, -1,
|
||||||
&result.at(0), len, nullptr, nullptr);
|
&result.at(0), len, nullptr, nullptr);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::vector<WCHAR> tows(const std::string& str) {
|
void tows(const char* mbs, WCHAR* wcs, size_t wcsLen) {
|
||||||
int strLen = ::MultiByteToWideChar(
|
|
||||||
CP_ACP, 0, str.c_str(), str.length() + 1,
|
|
||||||
nullptr, 0);
|
|
||||||
|
|
||||||
std::vector<WCHAR> wideStr(strLen);
|
|
||||||
|
|
||||||
::MultiByteToWideChar(
|
::MultiByteToWideChar(
|
||||||
CP_ACP, 0, str.c_str(), str.length() + 1,
|
CP_UTF8, 0, mbs, -1,
|
||||||
wideStr.data(), strLen);
|
wcs, wcsLen);
|
||||||
|
|
||||||
return wideStr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,12 @@ namespace dxvk::str {
|
|||||||
|
|
||||||
std::string fromws(const WCHAR *ws);
|
std::string fromws(const WCHAR *ws);
|
||||||
|
|
||||||
std::vector<WCHAR> tows(const std::string& str);
|
void tows(const char* mbs, WCHAR* wcs, size_t wcsLen);
|
||||||
|
|
||||||
|
template <size_t N>
|
||||||
|
void tows(const char* mbs, WCHAR (&wcs)[N]) {
|
||||||
|
return tows(mbs, wcs, N);
|
||||||
|
}
|
||||||
|
|
||||||
inline void format1(std::stringstream&) { }
|
inline void format1(std::stringstream&) { }
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user