diff options
author | Shauren <shauren.trinity@gmail.com> | 2023-11-24 20:01:17 +0100 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2023-11-24 20:01:17 +0100 |
commit | b299902881cb6525b5a6cc08c5721c0c1c7401ab (patch) | |
tree | d8fc9a61d307b0aa0ca3029ef065c5edc69cb1ab /src | |
parent | 3a50bc50a2a3898013404eb2319508521002984f (diff) |
Core/Locales: Set active code page and locale used by c string functions to utf8
Closes #29455
Diffstat (limited to 'src')
-rw-r--r-- | src/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/common/Time/Timezone.cpp | 14 | ||||
-rw-r--r-- | src/common/Utilities/Locales.cpp | 45 | ||||
-rw-r--r-- | src/common/Utilities/Locales.h | 31 | ||||
-rw-r--r-- | src/common/WindowsSettings.manifest | 13 | ||||
-rw-r--r-- | src/server/bnetserver/Main.cpp | 3 | ||||
-rw-r--r-- | src/server/game/AuctionHouse/AuctionHouseMgr.cpp | 1 | ||||
-rw-r--r-- | src/server/worldserver/Main.cpp | 3 | ||||
-rw-r--r-- | src/tools/map_extractor/System.cpp | 3 | ||||
-rw-r--r-- | src/tools/mmaps_generator/PathGenerator.cpp | 3 | ||||
-rw-r--r-- | src/tools/vmap4_assembler/VMapAssembler.cpp | 3 | ||||
-rw-r--r-- | src/tools/vmap4_extractor/vmapexport.cpp | 3 |
12 files changed, 117 insertions, 6 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0949c245635..1d2ea3093f9 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -12,6 +12,7 @@ if(WIN32 AND MSVC) set(sources_windows ${CMAKE_SOURCE_DIR}/src/common/Debugging/WheatyExceptionReport.cpp ${CMAKE_SOURCE_DIR}/src/common/Debugging/WheatyExceptionReport.h + ${CMAKE_SOURCE_DIR}/src/common/WindowsSettings.manifest ) endif() diff --git a/src/common/Time/Timezone.cpp b/src/common/Time/Timezone.cpp index f7acfe5df5c..3d09f8d7b0c 100644 --- a/src/common/Time/Timezone.cpp +++ b/src/common/Time/Timezone.cpp @@ -17,11 +17,12 @@ #include "Timezone.h" #include "Hash.h" +#include "Locales.h" #include "MapUtils.h" #include "Util.h" #include <boost/locale/date_time_facet.hpp> -#include <boost/locale/generator.hpp> #include <chrono> +#include <memory> #include <unordered_map> namespace @@ -95,7 +96,11 @@ std::unordered_map<uint32, Minutes, std::identity> InitTimezoneHashDb() return hashToOffset; } -std::unordered_map<uint32, Minutes, std::identity> const _timezoneOffsetsByHash = InitTimezoneHashDb(); +std::unordered_map<uint32, Minutes, std::identity> const& GetTimezoneOffsetsByHash() +{ + static std::unordered_map<uint32, Minutes, std::identity> timezoneMap = InitTimezoneHashDb(); + return timezoneMap; +} using ClientSupportedTimezone = std::pair<Minutes, std::string>; std::array<ClientSupportedTimezone, 11> const _clientSupportedTimezones = @@ -118,7 +123,7 @@ namespace Trinity::Timezone { Minutes GetOffsetByHash(uint32 hash) { - if (Minutes const* offset = Containers::MapGetValuePtr(_timezoneOffsetsByHash, hash)) + if (Minutes const* offset = Containers::MapGetValuePtr(GetTimezoneOffsetsByHash(), hash)) return *offset; return 0min; @@ -150,8 +155,7 @@ std::string GetSystemZoneName() #if TRINITY_PLATFORM == TRINITY_PLATFORM_WINDOWS return std::string(std::chrono::current_zone()->name()); #else - static std::locale calendarLocale = boost::locale::generator().generate(""); - std::unique_ptr<boost::locale::abstract_calendar> p(std::use_facet<class boost::locale::calendar_facet>(calendarLocale).create_calendar()); + std::unique_ptr<boost::locale::abstract_calendar> p(std::use_facet<class boost::locale::calendar_facet>(Locale::GetCalendarLocale()).create_calendar()); return p->get_timezone(); #endif } diff --git a/src/common/Utilities/Locales.cpp b/src/common/Utilities/Locales.cpp new file mode 100644 index 00000000000..b4048b9c3f3 --- /dev/null +++ b/src/common/Utilities/Locales.cpp @@ -0,0 +1,45 @@ +/* + * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information + + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "Locales.h" +#include <boost/locale/generator.hpp> + +namespace +{ +std::locale _utf8; +std::locale _calendar; +} + +void Trinity::Locale::Init() +{ + // Change global locale from "C" to UTF-8 for c runtime functions + _utf8 = std::locale(""); + std::locale::global(_utf8); + + boost::locale::generator g; + _calendar = g.generate(_utf8, ""); +} + +std::locale const& Trinity::Locale::GetGlobalLocale() +{ + return _utf8; +} + +std::locale const& Trinity::Locale::GetCalendarLocale() +{ + return _calendar; +} diff --git a/src/common/Utilities/Locales.h b/src/common/Utilities/Locales.h new file mode 100644 index 00000000000..b60ad0bbf2f --- /dev/null +++ b/src/common/Utilities/Locales.h @@ -0,0 +1,31 @@ +/* + * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information + + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef TRINITYCORE_LOCALE_H +#define TRINITYCORE_LOCALE_H + +#include "Define.h" +#include <locale> + +namespace Trinity::Locale +{ +TC_COMMON_API void Init(); +TC_COMMON_API std::locale const& GetGlobalLocale(); +TC_COMMON_API std::locale const& GetCalendarLocale(); +} + +#endif // TRINITYCORE_LOCALE_H diff --git a/src/common/WindowsSettings.manifest b/src/common/WindowsSettings.manifest new file mode 100644 index 00000000000..b7da14cfe5c --- /dev/null +++ b/src/common/WindowsSettings.manifest @@ -0,0 +1,13 @@ +<?xml version="1.0" encoding="UTF-8" standalone="yes"?> +<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1"> + <application xmlns="urn:schemas-microsoft-com:asm.v3"> + <windowsSettings> + <activeCodePage xmlns="http://schemas.microsoft.com/SMI/2019/WindowsSettings">UTF-8</activeCodePage> + </windowsSettings> + </application> + <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1"> + <application> + <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" /> <!-- Windows 10 --> + </application> + </compatibility> +</assembly> diff --git a/src/server/bnetserver/Main.cpp b/src/server/bnetserver/Main.cpp index 6b2e058262e..5d4fae4ce51 100644 --- a/src/server/bnetserver/Main.cpp +++ b/src/server/bnetserver/Main.cpp @@ -33,6 +33,7 @@ #include "GitRevision.h" #include "IPLocation.h" #include "IpNetwork.h" +#include "Locales.h" #include "LoginRESTService.h" #include "MySQLThreading.h" #include "OpenSSLCrypto.h" @@ -89,6 +90,8 @@ int main(int argc, char** argv) { signal(SIGABRT, &Trinity::AbortHandler); + Trinity::Locale::Init(); + auto configFile = fs::absolute(_TRINITY_BNET_CONFIG); auto configDir = fs::absolute(_TRINITY_BNET_CONFIG_DIR); std::string winServiceAction; diff --git a/src/server/game/AuctionHouse/AuctionHouseMgr.cpp b/src/server/game/AuctionHouse/AuctionHouseMgr.cpp index 262874e2481..8b2fa16029c 100644 --- a/src/server/game/AuctionHouse/AuctionHouseMgr.cpp +++ b/src/server/game/AuctionHouse/AuctionHouseMgr.cpp @@ -35,7 +35,6 @@ #include "ObjectMgr.h" #include "Player.h" #include "ScriptMgr.h" -#include "Timezone.h" #include "World.h" #include "WorldSession.h" #include "WowTime.h" diff --git a/src/server/worldserver/Main.cpp b/src/server/worldserver/Main.cpp index 3c3184f4ddc..eb5aba0e1aa 100644 --- a/src/server/worldserver/Main.cpp +++ b/src/server/worldserver/Main.cpp @@ -35,6 +35,7 @@ #include "InstanceLockMgr.h" #include "IoContext.h" #include "IpNetwork.h" +#include "Locales.h" #include "MapManager.h" #include "Metric.h" #include "MySQLThreading.h" @@ -130,6 +131,8 @@ extern int main(int argc, char** argv) { signal(SIGABRT, &Trinity::AbortHandler); + Trinity::Locale::Init(); + auto configFile = fs::absolute(_TRINITY_CORE_CONFIG); auto configDir = fs::absolute(_TRINITY_CORE_CONFIG_DIR); std::string winServiceAction; diff --git a/src/tools/map_extractor/System.cpp b/src/tools/map_extractor/System.cpp index 431ccf3029e..8d50b414ea6 100644 --- a/src/tools/map_extractor/System.cpp +++ b/src/tools/map_extractor/System.cpp @@ -23,6 +23,7 @@ #include "DBFilesClientList.h" #include "ExtractorDB2LoadInfo.h" #include "IteratorPair.h" +#include "Locales.h" #include "MapDefines.h" #include "StringFormat.h" #include "adt.h" @@ -1469,6 +1470,8 @@ static bool RetardCheck() int main(int argc, char * arg[]) { + Trinity::Locale::Init(); + Trinity::Banner::Show("Map & DBC Extractor", [](char const* text) { printf("%s\n", text); }, nullptr); PrintProgress = isatty(fileno(stdout)); diff --git a/src/tools/mmaps_generator/PathGenerator.cpp b/src/tools/mmaps_generator/PathGenerator.cpp index 59c087a514f..ac9df06265e 100644 --- a/src/tools/mmaps_generator/PathGenerator.cpp +++ b/src/tools/mmaps_generator/PathGenerator.cpp @@ -19,6 +19,7 @@ #include "DB2FileLoader.h" #include "DB2FileSystemSource.h" #include "ExtractorDB2LoadInfo.h" +#include "Locales.h" #include "MapBuilder.h" #include "PathCommon.h" #include "Timer.h" @@ -392,6 +393,8 @@ std::unordered_map<uint32, std::vector<uint32>> LoadMap(std::string const& local int main(int argc, char** argv) { + Trinity::Locale::Init(); + Trinity::Banner::Show("MMAP generator", [](char const* text) { printf("%s\n", text); }, nullptr); unsigned int threads = std::thread::hardware_concurrency(); diff --git a/src/tools/vmap4_assembler/VMapAssembler.cpp b/src/tools/vmap4_assembler/VMapAssembler.cpp index 2e55f16240b..aedafb6d3da 100644 --- a/src/tools/vmap4_assembler/VMapAssembler.cpp +++ b/src/tools/vmap4_assembler/VMapAssembler.cpp @@ -20,9 +20,12 @@ #include "TileAssembler.h" #include "Banner.h" +#include "Locales.h" int main(int argc, char* argv[]) { + Trinity::Locale::Init(); + Trinity::Banner::Show("VMAP assembler", [](char const* text) { std::cout << text << std::endl; }, nullptr); std::string src = "Buildings"; diff --git a/src/tools/vmap4_extractor/vmapexport.cpp b/src/tools/vmap4_extractor/vmapexport.cpp index ef54f40d49f..541d8136ec3 100644 --- a/src/tools/vmap4_extractor/vmapexport.cpp +++ b/src/tools/vmap4_extractor/vmapexport.cpp @@ -24,6 +24,7 @@ #include "StringFormat.h" #include "VMapDefinitions.h" #include "vmapexport.h" +#include "Locales.h" #include "wdtfile.h" #include "wmo.h" #include <algorithm> @@ -445,6 +446,8 @@ static bool RetardCheck() int main(int argc, char ** argv) { + Trinity::Locale::Init(); + Trinity::Banner::Show("VMAP data extractor", [](char const* text) { printf("%s\n", text); }, nullptr); bool success = true; |