Browse Source

Merge pull request #2096 from Vort/utf8

implement UTF-8 conversion with WinAPI for Windows platform
pull/2101/head
orignal 3 months ago committed by GitHub
parent
commit
d71f3d40fa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      Win32/Win32App.cpp
  2. 20
      libi2pd/FS.cpp

2
Win32/Win32App.cpp

@ -313,7 +313,7 @@ namespace win32
} }
case ID_DATADIR: case ID_DATADIR:
{ {
std::string datadir(i2p::fs::GetUTF8DataDir()); std::string datadir(i2p::fs::GetDataDir());
ShellExecute(NULL, "explore", datadir.c_str(), NULL, NULL, SW_SHOWNORMAL); ShellExecute(NULL, "explore", datadir.c_str(), NULL, NULL, SW_SHOWNORMAL);
return 0; return 0;
} }

20
libi2pd/FS.cpp

@ -61,15 +61,17 @@ namespace fs {
const std::string GetUTF8DataDir () { const std::string GetUTF8DataDir () {
#ifdef _WIN32 #ifdef _WIN32
#if ((BOOST_VERSION >= 108500) || STD_FILESYSTEM) int size = MultiByteToWideChar(CP_ACP, 0,
fs_lib::path path (dataDir); dataDir.c_str(), dataDir.size(), nullptr, 0);
#else std::wstring utf16Str(size, L'\0');
fs_lib::wpath path (dataDir); MultiByteToWideChar(CP_ACP, 0,
#endif dataDir.c_str(), dataDir.size(), &utf16Str[0], size);
auto loc = fs_lib::path::imbue(std::locale( std::locale(), new std::codecvt_utf8_utf16<wchar_t>() ) ); // convert path to UTF-8 int utf8Size = WideCharToMultiByte(CP_UTF8, 0,
auto dataDirUTF8 = path.string(); utf16Str.c_str(), utf16Str.size(), nullptr, 0, nullptr, nullptr);
fs_lib::path::imbue(loc); // Return locale settings back std::string utf8Str(utf8Size, '\0');
return dataDirUTF8; WideCharToMultiByte(CP_UTF8, 0,
utf16Str.c_str(), utf16Str.size(), &utf8Str[0], utf8Size, nullptr, nullptr);
return utf8Str;
#else #else
return dataDir; // linux, osx, android uses UTF-8 by default return dataDir; // linux, osx, android uses UTF-8 by default
#endif #endif

Loading…
Cancel
Save