Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/Scenarios/d) Leaving Harbour/description.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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.
9 changes: 3 additions & 6 deletions src/IniFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(""));
}
Expand Down
32 changes: 25 additions & 7 deletions src/ScenarioChoice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@
#include <iostream>
#include <fstream>

#ifdef _WIN32
// For UTF8 to ANSI conversion
#include <codecvt>
#include <locale>
#include <vector>
#endif // _WIN32

//using namespace irr;

ScenarioChoice::ScenarioChoice(irr::IrrlichtDevice* device, Lang* language)
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -216,17 +226,14 @@ void ScenarioChoice::getScenarioList(std::vector<std::string>&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(""));
}
Expand All @@ -243,6 +250,17 @@ void ScenarioChoice::getScenarioList(std::vector<std::string>&scenarioList, std:
}
descriptionStream.close();
}

#ifdef _WIN32
// If Windows, convert the UTF8 string to ANSI:
std::wstring_convert<std::codecvt_utf8<wchar_t>> wconv;
std::wstring wstr = wconv.from_bytes(descriptionLines);
// wstring to string
std::vector<char> buf(wstr.size());
std::use_facet<std::ctype<wchar_t>>(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

}
Expand Down
5 changes: 5 additions & 0 deletions src/controller/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 7 additions & 6 deletions src/editor/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(""));
}
Expand Down
5 changes: 5 additions & 0 deletions src/iniEditor/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/launcher/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/multiplayerHub/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/repeater/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading