mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-25 22:42:04 +02:00
fix Chinese encoding problem in GBK
This commit is contained in:
@@ -14,6 +14,8 @@
|
|||||||
|
|
||||||
#include "../ExceptionsCommon.h"
|
#include "../ExceptionsCommon.h"
|
||||||
|
|
||||||
|
#include <boost/locale/encoding_utf.hpp>
|
||||||
|
|
||||||
VCMI_LIB_NAMESPACE_BEGIN
|
VCMI_LIB_NAMESPACE_BEGIN
|
||||||
|
|
||||||
CFilesystemLoader::CFilesystemLoader(std::string _mountPoint, boost::filesystem::path baseDirectory, size_t depth, bool initial):
|
CFilesystemLoader::CFilesystemLoader(std::string _mountPoint, boost::filesystem::path baseDirectory, size_t depth, bool initial):
|
||||||
@@ -91,20 +93,21 @@ bool CFilesystemLoader::createResource(const std::string & requestedFilename, bo
|
|||||||
}
|
}
|
||||||
|
|
||||||
filename = filename.substr(mountPoint.size());
|
filename = filename.substr(mountPoint.size());
|
||||||
|
std::wstring filePath = boost::locale::conv::utf_to_utf<wchar_t>(filename);
|
||||||
|
|
||||||
if (!update)
|
if (!update)
|
||||||
{
|
{
|
||||||
// create folders if not exists
|
// create folders if not exists
|
||||||
boost::filesystem::path p((baseDirectory / filename).c_str());
|
boost::filesystem::path p((baseDirectory / filePath).c_str());
|
||||||
boost::filesystem::create_directories(p.parent_path());
|
boost::filesystem::create_directories(p.parent_path());
|
||||||
|
|
||||||
// create file, if not exists
|
// create file, if not exists
|
||||||
std::ofstream file((baseDirectory / filename).c_str(), std::ofstream::binary);
|
std::ofstream file((baseDirectory / filePath).c_str(), std::ofstream::binary);
|
||||||
|
|
||||||
if (!file.is_open())
|
if (!file.is_open())
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
fileList[resID] = filename;
|
fileList[resID] = filePath;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -173,19 +176,26 @@ std::unordered_map<ResourcePath, boost::filesystem::path> CFilesystemLoader::lis
|
|||||||
filename = it->path().filename();
|
filename = it->path().filename();
|
||||||
|
|
||||||
std::string resName;
|
std::string resName;
|
||||||
|
|
||||||
|
#ifdef VCMI_WINDOWS
|
||||||
|
std::string filenameUtf8 = boost::locale::conv::utf_to_utf<char>(filename.native());
|
||||||
|
#else
|
||||||
|
std::string filenameUtf8 = filename.string();
|
||||||
|
#endif
|
||||||
|
|
||||||
if (boost::filesystem::path::preferred_separator != '/')
|
if (boost::filesystem::path::preferred_separator != '/')
|
||||||
{
|
{
|
||||||
// resource names are using UNIX slashes (/)
|
// resource names are using UNIX slashes (/)
|
||||||
resName.reserve(resName.size() + filename.native().size());
|
resName.reserve(resName.size() + filename.native().size());
|
||||||
resName = mountPoint;
|
resName = mountPoint;
|
||||||
for (const char c : filename.string())
|
for (const char c : filenameUtf8)
|
||||||
if (c != boost::filesystem::path::preferred_separator)
|
if (c != boost::filesystem::path::preferred_separator)
|
||||||
resName.push_back(c);
|
resName.push_back(c);
|
||||||
else
|
else
|
||||||
resName.push_back('/');
|
resName.push_back('/');
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
resName = mountPoint + filename.string();
|
resName = mountPoint + filenameUtf8;
|
||||||
|
|
||||||
fileList[ResourcePath(resName, type)] = std::move(filename);
|
fileList[ResourcePath(resName, type)] = std::move(filename);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,6 +27,8 @@
|
|||||||
#include "../IGameSettings.h"
|
#include "../IGameSettings.h"
|
||||||
#include "../CConfigHandler.h"
|
#include "../CConfigHandler.h"
|
||||||
|
|
||||||
|
#include <boost/locale/encoding_utf.hpp>
|
||||||
|
|
||||||
VCMI_LIB_NAMESPACE_BEGIN
|
VCMI_LIB_NAMESPACE_BEGIN
|
||||||
|
|
||||||
CMapInfo::CMapInfo()
|
CMapInfo::CMapInfo()
|
||||||
@@ -40,13 +42,23 @@ CMapInfo::~CMapInfo()
|
|||||||
vstd::clear_pointer(scenarioOptionsOfSave);
|
vstd::clear_pointer(scenarioOptionsOfSave);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string CMapInfo::getFullFileURI(const ResourcePath & file) const
|
||||||
|
{
|
||||||
|
auto path = boost::filesystem::canonical(*CResourceHandler::get()->getResourceName(file));
|
||||||
|
#ifdef VCMI_WINDOWS
|
||||||
|
return boost::locale::conv::utf_to_utf<char>(path.native());
|
||||||
|
#else
|
||||||
|
return path.string();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void CMapInfo::mapInit(const std::string & fname)
|
void CMapInfo::mapInit(const std::string & fname)
|
||||||
{
|
{
|
||||||
fileURI = fname;
|
fileURI = fname;
|
||||||
CMapService mapService;
|
CMapService mapService;
|
||||||
ResourcePath resource = ResourcePath(fname, EResType::MAP);
|
ResourcePath resource = ResourcePath(fname, EResType::MAP);
|
||||||
originalFileURI = resource.getOriginalName();
|
originalFileURI = resource.getOriginalName();
|
||||||
fullFileURI = boost::filesystem::canonical(*CResourceHandler::get()->getResourceName(resource)).string();
|
fullFileURI = getFullFileURI(resource);
|
||||||
mapHeader = mapService.loadMapHeader(resource);
|
mapHeader = mapService.loadMapHeader(resource);
|
||||||
lastWrite = boost::filesystem::last_write_time(*CResourceHandler::get()->getResourceName(resource));
|
lastWrite = boost::filesystem::last_write_time(*CResourceHandler::get()->getResourceName(resource));
|
||||||
date = TextOperations::getFormattedDateTimeLocal(lastWrite);
|
date = TextOperations::getFormattedDateTimeLocal(lastWrite);
|
||||||
@@ -62,7 +74,7 @@ void CMapInfo::saveInit(const ResourcePath & file)
|
|||||||
lf >> *(mapHeader) >> scenarioOptionsOfSave;
|
lf >> *(mapHeader) >> scenarioOptionsOfSave;
|
||||||
fileURI = file.getName();
|
fileURI = file.getName();
|
||||||
originalFileURI = file.getOriginalName();
|
originalFileURI = file.getOriginalName();
|
||||||
fullFileURI = boost::filesystem::canonical(*CResourceHandler::get()->getResourceName(file)).string();
|
fullFileURI = getFullFileURI(file);
|
||||||
countPlayers();
|
countPlayers();
|
||||||
lastWrite = boost::filesystem::last_write_time(*CResourceHandler::get()->getResourceName(file));
|
lastWrite = boost::filesystem::last_write_time(*CResourceHandler::get()->getResourceName(file));
|
||||||
date = TextOperations::getFormattedDateTimeLocal(lastWrite);
|
date = TextOperations::getFormattedDateTimeLocal(lastWrite);
|
||||||
@@ -76,7 +88,7 @@ void CMapInfo::campaignInit()
|
|||||||
{
|
{
|
||||||
ResourcePath resource = ResourcePath(fileURI, EResType::CAMPAIGN);
|
ResourcePath resource = ResourcePath(fileURI, EResType::CAMPAIGN);
|
||||||
originalFileURI = resource.getOriginalName();
|
originalFileURI = resource.getOriginalName();
|
||||||
fullFileURI = boost::filesystem::canonical(*CResourceHandler::get()->getResourceName(resource)).string();
|
fullFileURI = getFullFileURI(resource);
|
||||||
campaign = CampaignHandler::getHeader(fileURI);
|
campaign = CampaignHandler::getHeader(fileURI);
|
||||||
lastWrite = boost::filesystem::last_write_time(*CResourceHandler::get()->getResourceName(resource));
|
lastWrite = boost::filesystem::last_write_time(*CResourceHandler::get()->getResourceName(resource));
|
||||||
date = TextOperations::getFormattedDateTimeLocal(lastWrite);
|
date = TextOperations::getFormattedDateTimeLocal(lastWrite);
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ public:
|
|||||||
CMapInfo &operator=(CMapInfo &&other) = delete;
|
CMapInfo &operator=(CMapInfo &&other) = delete;
|
||||||
CMapInfo &operator=(const CMapInfo &other) = delete;
|
CMapInfo &operator=(const CMapInfo &other) = delete;
|
||||||
|
|
||||||
|
std::string CMapInfo::getFullFileURI(const ResourcePath& file) const;
|
||||||
void mapInit(const std::string & fname);
|
void mapInit(const std::string & fname);
|
||||||
void saveInit(const ResourcePath & file);
|
void saveInit(const ResourcePath & file);
|
||||||
void campaignInit();
|
void campaignInit();
|
||||||
|
|||||||
Reference in New Issue
Block a user