From 3a709f60eb466129c36210d917bd35df528930ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20Gallou=C3=ABt?= Date: Wed, 3 Dec 2025 13:23:23 +0100 Subject: [PATCH] common: use native MultiByteToWideChar MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `std::codecvt_utf8` is deprecated and produces warnings: common/common.cpp:792:31: warning: 'codecvt_utf8' is deprecated [-Wdeprecated-declarations] 792 | std::wstring_convert> converter; | Signed-off-by: Adrien Gallouët --- common/common.cpp | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/common/common.cpp b/common/common.cpp index f07af1d8625..a42f4884359 100644 --- a/common/common.cpp +++ b/common/common.cpp @@ -786,11 +786,29 @@ bool fs_validate_filename(const std::string & filename, bool allow_subdirs) { #include +#ifdef _WIN32 +static std::wstring utf8_to_wstring(const std::string & str) { + if (str.empty()) { + return std::wstring(); + } + + int size = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), (int)str.size(), NULL, 0); + + if (size <= 0) { + return std::wstring(); + } + + std::wstring wstr(size, 0); + MultiByteToWideChar(CP_UTF8, 0, str.c_str(), (int)str.size(), &wstr[0], size); + + return wstr; +} +#endif + // returns true if successful, false otherwise bool fs_create_directory_with_parents(const std::string & path) { #ifdef _WIN32 - std::wstring_convert> converter; - std::wstring wpath = converter.from_bytes(path); + std::wstring wpath = utf8_to_wstring(path); // if the path already exists, check whether it's a directory const DWORD attributes = GetFileAttributesW(wpath.c_str());