diff --git a/src/fs.h b/src/fs.h --- a/src/fs.h +++ b/src/fs.h @@ -38,6 +38,8 @@ void *hFile = (void *)-1; #endif }; + +std::string get_filesystem_error_message(const fs::filesystem_error &e); }; // namespace fsbridge #endif // BITCOIN_FS_H diff --git a/src/fs.cpp b/src/fs.cpp --- a/src/fs.cpp +++ b/src/fs.cpp @@ -96,4 +96,22 @@ } #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 +} + } // namespace fsbridge diff --git a/src/rpc/protocol.cpp b/src/rpc/protocol.cpp --- a/src/rpc/protocol.cpp +++ b/src/rpc/protocol.cpp @@ -132,7 +132,7 @@ fs::remove(GetAuthCookieFile()); } catch (const fs::filesystem_error &e) { LogPrintf("%s: Unable to remove random auth cookie file: %s\n", - __func__, e.what()); + __func__, fsbridge::get_filesystem_error_message(e)); } } diff --git a/src/wallet/db.cpp b/src/wallet/db.cpp --- a/src/wallet/db.cpp +++ b/src/wallet/db.cpp @@ -944,7 +944,8 @@ return true; } catch (const fs::filesystem_error &e) { LogPrintf("error copying %s to %s - %s\n", strFile, - pathDest.string(), e.what()); + pathDest.string(), + fsbridge::get_filesystem_error_message(e)); return false; } } diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -4345,8 +4345,9 @@ return false; } } catch (const fs::filesystem_error &e) { - error_string = strprintf("Error loading wallet %s. %s", - location.GetName(), e.what()); + error_string = + strprintf("Error loading wallet %s. %s", location.GetName(), + fsbridge::get_filesystem_error_message(e)); return false; }