mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-14 12:43:40 +02:00
Merge #14192: utils: Convert fs::filesystem_error messages from local multibyte to utf-8 on Windows
e221368932 utils: Convert fs error messages from multibyte to utf-8 (Chun Kuan Lee)
Pull request description:
Before:

After:

Tree-SHA512: 0a598bd159286f6784d117b8a24888b2650d5402d687ab0e8d0849e0c3d53797e266647d8177bb6614307c9598019cd7477311bb9895b1bb52a6bd77b460fda1
This commit is contained in:
commit
d73205ef36
5 changed files with 21 additions and 3 deletions
16
src/fs.cpp
16
src/fs.cpp
|
|
@ -97,4 +97,20 @@ bool FileLock::TryLock()
|
|||
}
|
||||
#endif
|
||||
|
||||
std::string get_filesystem_error_message(const fs::filesystem_error& e)
|
||||
{
|
||||
#ifndef WIN32
|
||||
return e.what();
|
||||
#else
|
||||
// Convert from Multi Byte to utf-16
|
||||
std::string mb_string(e.what());
|
||||
int size = MultiByteToWideChar(CP_ACP, 0, mb_string.c_str(), mb_string.size(), nullptr, 0);
|
||||
|
||||
std::wstring utf16_string(size, L'\0');
|
||||
MultiByteToWideChar(CP_ACP, 0, mb_string.c_str(), mb_string.size(), &*utf16_string.begin(), size);
|
||||
// Convert from utf-16 to utf-8
|
||||
return std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t>().to_bytes(utf16_string);
|
||||
#endif
|
||||
}
|
||||
|
||||
} // fsbridge
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue