Adding support of UTF8 file name processing in mio on windows

Contributing back changes from app.
This commit is contained in:
Shivendra Agarwal 2020-11-06 10:56:36 +05:30 committed by GitHub
parent 8c0d3c7c23
commit ce1bf19d40
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -794,6 +794,16 @@ inline DWORD int64_low(int64_t n) noexcept
return n & 0xffffffff;
}
std::wstring s2ws(const std::string& s)
{
if (s.empty())
return{};
const auto sLength = static_cast<int>(s.length());
auto buf = std::vector<wchar_t>(sLength);
const auto wideCharCount = MultiByteToWideChar(CP_UTF8, 0, s.c_str(), sLength, buf.data(), sLength);
return std::wstring(buf.data(), wideCharCount);
}
template<
typename String,
typename = typename std::enable_if<
@ -801,7 +811,7 @@ template<
>::type
> file_handle_type open_file_helper(const String& path, const access_mode mode)
{
return ::CreateFileA(c_str(path),
return ::CreateFileW(s2ws(path).c_str(),
mode == access_mode::read ? GENERIC_READ : GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
0,