mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-27 22:49:25 +02:00
Fix build
This commit is contained in:
@@ -115,6 +115,15 @@ std::wstring VCMIDirsWIN32::utf8ToWstring(const std::string& str) const
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static std::string pathToUtf8(const bfs::path& path)
|
||||||
|
{
|
||||||
|
std::wstring wstr = path.wstring();
|
||||||
|
int size = WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), -1, nullptr, 0, nullptr, nullptr);
|
||||||
|
std::string result(size - 1, 0);
|
||||||
|
WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), -1, result.data(), size, nullptr, nullptr);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
void VCMIDirsWIN32::loadDirsJsonIfNeeded() const
|
void VCMIDirsWIN32::loadDirsJsonIfNeeded() const
|
||||||
{
|
{
|
||||||
if (dirsConfig.has_value())
|
if (dirsConfig.has_value())
|
||||||
@@ -130,7 +139,7 @@ void VCMIDirsWIN32::loadDirsJsonIfNeeded() const
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ifstream in(configPath.wstring(), std::ios::binary);
|
std::ifstream in(pathToUtf8(configPath), std::ios::binary);
|
||||||
if (!in)
|
if (!in)
|
||||||
{
|
{
|
||||||
dirsConfig = std::nullopt;
|
dirsConfig = std::nullopt;
|
||||||
@@ -138,13 +147,7 @@ void VCMIDirsWIN32::loadDirsJsonIfNeeded() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string buffer((std::istreambuf_iterator<char>(in)), {});
|
std::string buffer((std::istreambuf_iterator<char>(in)), {});
|
||||||
std::wstring wstr = configPath.wstring();
|
dirsConfig = JsonNode(reinterpret_cast<const std::byte*>(buffer.data()), buffer.size(), pathToUtf8(configPath));
|
||||||
|
|
||||||
int size = WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), -1, nullptr, 0, nullptr, nullptr);
|
|
||||||
std::string utf8path(size - 1, 0);
|
|
||||||
WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), -1, utf8path.data(), size, nullptr, nullptr);
|
|
||||||
|
|
||||||
dirsConfig = JsonNode(reinterpret_cast<const std::byte*>(buffer.data()), buffer.size(), utf8path);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bfs::path VCMIDirsWIN32::getPathFromConfigOrDefault(const std::string& key, const std::function<bfs::path()>& fallbackFunc) const
|
bfs::path VCMIDirsWIN32::getPathFromConfigOrDefault(const std::string& key, const std::function<bfs::path()>& fallbackFunc) const
|
||||||
|
|||||||
Reference in New Issue
Block a user