diff --git a/bin/Scenarios/d) Leaving Harbour/description.ini b/bin/Scenarios/d) Leaving Harbour/description.ini index 08ed7e3c1..9ae8680e4 100644 --- a/bin/Scenarios/d) Leaving Harbour/description.ini +++ b/bin/Scenarios/d) Leaving Harbour/description.ini @@ -3,6 +3,6 @@ Leaving Santa Catalina Harbour. Safely leave Santa Catalina harbour, maintaining a good lookout, and taking appropriate action. -Aim to maintain a course of 196º (T). Having proceeded +Aim to maintain a course of 196º (T). Having proceeded for 0.5 nm on this course, turn to starboard and come alongside the anchored submarine to transfer ammunition. \ No newline at end of file diff --git a/src/IniFile.cpp b/src/IniFile.cpp index f39df5c5c..5e7fd71ce 100644 --- a/src/IniFile.cpp +++ b/src/IniFile.cpp @@ -55,17 +55,14 @@ bool IniCache::readFile(const std::string& fileName) std::ifstream file (fileName.c_str()); - //Set UTF-8 on Linux/OSX etc + #ifndef _WIN32 + //Get currently used locale (should be for UTF-8), and use for file reading try { -# ifdef __APPLE__ - char* thisLocale = setlocale(LC_ALL, ""); + char* thisLocale = setlocale(LC_CTYPE, NULL); if (thisLocale) { file.imbue(std::locale(thisLocale)); } -# else - file.imbue(std::locale("en_US.UTF8")); -# endif } catch (const std::runtime_error& runtimeError) { file.imbue(std::locale("")); } diff --git a/src/ScenarioChoice.cpp b/src/ScenarioChoice.cpp index 9ac609d54..63cd1aaea 100644 --- a/src/ScenarioChoice.cpp +++ b/src/ScenarioChoice.cpp @@ -23,6 +23,13 @@ #include #include +#ifdef _WIN32 +// For UTF8 to ANSI conversion +#include +#include +#include +#endif // _WIN32 + //using namespace irr; ScenarioChoice::ScenarioChoice(irr::IrrlichtDevice* device, Lang* language) @@ -113,7 +120,10 @@ void ScenarioChoice::chooseScenario(std::string& scenarioName, std::string& host //Update the description text description->setText(L""); if (scenarioDescription.size() > currentSelection && currentSelection>=0) { - description->setText(irr::core::stringw(scenarioDescription.at(currentSelection).c_str()).c_str()); + // Convert, allowing UTF-8 + irr::core::stringw description_stringw; + irr::core::multibyteToWString(description_stringw, scenarioDescription.at(currentSelection).c_str()); + description->setText(description_stringw.c_str()); } currentSelection = descriptionScenario; } @@ -216,17 +226,14 @@ void ScenarioChoice::getScenarioList(std::vector&scenarioList, std: irr::io::path descriptionFilePath = fileName; irr::io::path descriptionFilename = descriptionFilePath.append("/description.ini"); std::ifstream descriptionStream (descriptionFilename.c_str()); - //Set UTF-8 on Linux/OSX etc #ifndef _WIN32 + //Get currently used locale (should be for UTF-8), and use for file reading try { - # ifdef __APPLE__ - char* thisLocale = setlocale(LC_ALL, ""); + char* thisLocale = setlocale(LC_CTYPE, NULL); if (thisLocale) { descriptionStream.imbue(std::locale(thisLocale)); } - # else - descriptionStream.imbue(std::locale("en_US.UTF8")); - # endif + } catch (const std::runtime_error& runtimeError) { descriptionStream.imbue(std::locale("")); } @@ -243,6 +250,17 @@ void ScenarioChoice::getScenarioList(std::vector&scenarioList, std: } descriptionStream.close(); } + + #ifdef _WIN32 + // If Windows, convert the UTF8 string to ANSI: + std::wstring_convert> wconv; + std::wstring wstr = wconv.from_bytes(descriptionLines); + // wstring to string + std::vector buf(wstr.size()); + std::use_facet>(std::locale(".1252")).narrow(wstr.data(), wstr.data() + wstr.size(), '?', buf.data()); + descriptionLines = std::string(buf.data(), buf.size()); + #endif + scenarioDescription.push_back(descriptionLines); //Add even if empty } diff --git a/src/controller/main.cpp b/src/controller/main.cpp index 8c3dd5db3..32c6b5e0f 100644 --- a/src/controller/main.cpp +++ b/src/controller/main.cpp @@ -50,6 +50,11 @@ namespace IniFile { int main (int argc, char ** argv) { + // For POSIX, set default locale character type (UTF-8) + #ifndef _WIN32 + setlocale(LC_ALL, ""); + #endif + #ifdef FOR_DEB chdir("/usr/share/bridgecommand"); #endif // FOR_DEB diff --git a/src/editor/main.cpp b/src/editor/main.cpp index 7d2233bb7..12fb23496 100644 --- a/src/editor/main.cpp +++ b/src/editor/main.cpp @@ -289,6 +289,11 @@ void checkUserScenarioDir(void) int main (int argc, char ** argv) { + // For POSIX, set default locale character type (UTF-8) + #ifndef _WIN32 + setlocale(LC_ALL, ""); + #endif + #ifdef FOR_DEB chdir("/usr/share/bridgecommand"); #endif // FOR_DEB @@ -626,17 +631,13 @@ int main (int argc, char ** argv) //Load description information std::ifstream descriptionStream (descriptionFilename.c_str()); - //Set UTF-8 on Linux/OSX etc #ifndef _WIN32 + //Get currently used locale (should be for UTF-8), and use for file reading try { - # ifdef __APPLE__ - char* thisLocale = setlocale(LC_ALL, ""); + char* thisLocale = setlocale(LC_CTYPE, NULL); if (thisLocale) { descriptionStream.imbue(std::locale(thisLocale)); } - # else - descriptionStream.imbue(std::locale("en_US.UTF8")); - # endif } catch (const std::runtime_error& runtimeError) { descriptionStream.imbue(std::locale("")); } diff --git a/src/iniEditor/main.cpp b/src/iniEditor/main.cpp index 349a4ddef..4909cc2b8 100644 --- a/src/iniEditor/main.cpp +++ b/src/iniEditor/main.cpp @@ -200,6 +200,11 @@ int findCharOccurrences(std::string inputString, std::string findStr) int main (int argc, char ** argv) { + // For POSIX, set default locale character type (UTF-8) + #ifndef _WIN32 + setlocale(LC_ALL, ""); + #endif + #ifdef FOR_DEB chdir("/usr/share/bridgecommand"); #endif // FOR_DEB diff --git a/src/launcher/main.cpp b/src/launcher/main.cpp index 8545f0f4c..b2e40b4b4 100644 --- a/src/launcher/main.cpp +++ b/src/launcher/main.cpp @@ -368,6 +368,11 @@ class Receiver : public irr::IEventReceiver int main (int argc, char ** argv) { + // For POSIX, set default locale character type (UTF-8) + #ifndef _WIN32 + setlocale(LC_ALL, ""); + #endif + if ((argc>1)&&(strcmp(argv[1],"--version")==0)) { std::cout << LONGVERSION << std::endl; exit(EXIT_SUCCESS); diff --git a/src/main.cpp b/src/main.cpp index c120964e7..7b6fde93f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -400,6 +400,11 @@ int main(int argc, char ** argv) IPROF_FUNC; #endif + // For POSIX, set default locale character type (UTF-8) + #ifndef _WIN32 + setlocale(LC_ALL, ""); + #endif + #ifdef FOR_DEB chdir("/usr/share/bridgecommand"); #endif // FOR_DEB diff --git a/src/multiplayerHub/main.cpp b/src/multiplayerHub/main.cpp index 3204e1165..9ec1920ee 100644 --- a/src/multiplayerHub/main.cpp +++ b/src/multiplayerHub/main.cpp @@ -76,6 +76,11 @@ std::string makeTimeString(uint64_t absoluteTime, uint64_t offsetTime, irr::f32 int main() { + // For POSIX, set default locale character type (UTF-8) + #ifndef _WIN32 + setlocale(LC_ALL, ""); + #endif + #ifdef FOR_DEB chdir("/usr/share/bridgecommand"); #endif // FOR_DEB diff --git a/src/repeater/main.cpp b/src/repeater/main.cpp index 7ccee51b2..0dc14ce49 100644 --- a/src/repeater/main.cpp +++ b/src/repeater/main.cpp @@ -89,6 +89,11 @@ struct cMonitorsVec int main (int argc, char ** argv) { + // For POSIX, set default locale character type (UTF-8) + #ifndef _WIN32 + setlocale(LC_ALL, ""); + #endif + #ifdef FOR_DEB chdir("/usr/share/bridgecommand"); #endif // FOR_DEB