From e2213689328f8ba42af1d32d12c7b78a71f1ddc7 Mon Sep 17 00:00:00 2001 From: Chun Kuan Lee Date: Tue, 11 Sep 2018 02:08:56 +0800 Subject: utils: Convert fs error messages from multibyte to utf-8 --- src/fs.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/fs.cpp') diff --git a/src/fs.cpp b/src/fs.cpp index 2dbc13643b..1a221788b8 100644 --- a/src/fs.cpp +++ b/src/fs.cpp @@ -92,4 +92,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, wchar_t>().to_bytes(utf16_string); +#endif +} + } // fsbridge -- cgit v1.2.3