diff options
-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/authserver/Main.cpp | 3 | ||||
-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 |
11 files changed, 117 insertions, 5 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 6bc5773edc3..9748078fe9f 100644 --- a/src/common/Time/Timezone.cpp +++ b/src/common/Time/Timezone.cpp @@ -17,12 +17,13 @@ #include "Timezone.h" #include "Hash.h" +#include "Locales.h" #include "MapUtils.h" #include "StringConvert.h" #include "Util.h" #include <boost/locale/date_time_facet.hpp> -#include <boost/locale/generator.hpp> #include <chrono> +#include <memory> #include <unordered_map> namespace @@ -96,7 +97,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 = @@ -119,7 +124,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; @@ -151,8 +156,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/authserver/Main.cpp b/src/server/authserver/Main.cpp index 2fd352be0ed..c4f4873ff57 100644 --- a/src/server/authserver/Main.cpp +++ b/src/server/authserver/Main.cpp @@ -33,6 +33,7 @@ #include "IoContext.h" #include "IPLocation.h" #include "GitRevision.h" +#include "Locales.h" #include "MySQLThreading.h" #include "OpenSSLCrypto.h" #include "ProcessPriority.h" @@ -85,6 +86,8 @@ int main(int argc, char** argv) Trinity::Impl::CurrentServerProcessHolder::_type = SERVER_PROCESS_AUTHSERVER; signal(SIGABRT, &Trinity::AbortHandler); + Trinity::Locale::Init(); + auto configFile = fs::absolute(_TRINITY_REALM_CONFIG); std::string configService; auto vm = GetConsoleArguments(argc, argv, configFile, configService); diff --git a/src/server/worldserver/Main.cpp b/src/server/worldserver/Main.cpp index 86d8ac7d18d..39a9ae7d6f3 100644 --- a/src/server/worldserver/Main.cpp +++ b/src/server/worldserver/Main.cpp @@ -33,6 +33,7 @@ #include "GitRevision.h" #include "InstanceSaveMgr.h" #include "IoContext.h" +#include "Locales.h" #include "MapManager.h" #include "Metric.h" #include "MySQLThreading.h" @@ -126,6 +127,8 @@ extern int main(int argc, char** argv) Trinity::Impl::CurrentServerProcessHolder::_type = SERVER_PROCESS_WORLDSERVER; signal(SIGABRT, &Trinity::AbortHandler); + Trinity::Locale::Init(); + auto configFile = fs::absolute(_TRINITY_CORE_CONFIG); std::string configService; diff --git a/src/tools/map_extractor/System.cpp b/src/tools/map_extractor/System.cpp index b92f0d1668a..d5210560b10 100644 --- a/src/tools/map_extractor/System.cpp +++ b/src/tools/map_extractor/System.cpp @@ -17,6 +17,7 @@ #include "dbcfile.h" #include "Banner.h" +#include "Locales.h" #include "mpq_libmpq04.h" #include "StringFormat.h" @@ -1120,6 +1121,8 @@ inline void CloseMPQFiles() int main(int argc, char * arg[]) { + Trinity::Locale::Init(); + Trinity::Banner::Show("Map & DBC Extractor", [](char const* text) { printf("%s\n", text); }, nullptr); HandleArgs(argc, arg); diff --git a/src/tools/mmaps_generator/PathGenerator.cpp b/src/tools/mmaps_generator/PathGenerator.cpp index 590177dc8e5..d8693bce323 100644 --- a/src/tools/mmaps_generator/PathGenerator.cpp +++ b/src/tools/mmaps_generator/PathGenerator.cpp @@ -17,6 +17,7 @@ #include "Banner.h" #include "DBCFileLoader.h" +#include "Locales.h" #include "MapBuilder.h" #include "PathCommon.h" #include "Timer.h" @@ -297,6 +298,8 @@ std::unordered_map<uint32, uint8> LoadLiquid() 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 f82553e29cc..4b60199260f 100644 --- a/src/tools/vmap4_extractor/vmapexport.cpp +++ b/src/tools/vmap4_extractor/vmapexport.cpp @@ -20,6 +20,7 @@ #include "dbcfile.h" #include "StringFormat.h" #include "vmapexport.h" +#include "Locales.h" #include "wdtfile.h" #include "wmo.h" #include "mpq_libmpq04.h" @@ -406,6 +407,8 @@ bool processArgv(int argc, char ** argv, const char *versionString) 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; |