aboutsummaryrefslogtreecommitdiff
path: root/src/fs.cpp
diff options
context:
space:
mode:
authorChun Kuan Lee <ken2812221@gmail.com>2018-09-11 02:08:56 +0800
committerChun Kuan Lee <ken2812221@gmail.com>2018-09-11 03:11:39 +0800
commite2213689328f8ba42af1d32d12c7b78a71f1ddc7 (patch)
treeba99e353bfa32fe4e0ee0ed86480acfc9a9e7654 /src/fs.cpp
parent6eeac2e628b5332dcaee60e5c83861c94e44d04d (diff)
utils: Convert fs error messages from multibyte to utf-8
Diffstat (limited to 'src/fs.cpp')
-rw-r--r--src/fs.cpp16
1 files changed, 16 insertions, 0 deletions
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<std::codecvt_utf8_utf16<wchar_t>, wchar_t>().to_bytes(utf16_string);
+#endif
+}
+
} // fsbridge