Skip to content

Commit

Permalink
Unicode Support on Windows
Browse files Browse the repository at this point in the history
Fixes eclipse-ecal#417 

Changed hopefully all Windows calls to ASCII-fuctions (like `CreateDirectoryA` or `open()`) by WideString variants. eCAL will from now on assume everything to be UTF-8 encoded, which should make perfect sense in 2022.
  • Loading branch information
FlorianReimold authored Jan 27, 2022
1 parent 33de7e8 commit 3e58c41
Show file tree
Hide file tree
Showing 35 changed files with 739 additions and 293 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/build-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ jobs:
-DECAL_THIRDPARTY_BUILD_HDF5=OFF \
-DECAL_THIRDPARTY_BUILD_RECYCLE=ON \
-DECAL_THIRDPARTY_BUILD_TCPUB=ON \
-DCMAKE_BUILD_TYPE=Release
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_CXX_STANDARD=14
sudo mkdir /etc/ecal
sudo cp "$GITHUB_WORKSPACE/ecal/core/cfg/ecal.ini" /etc/ecal
shell: bash
Expand Down
1 change: 1 addition & 0 deletions app/play/play_cli/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ target_link_libraries(${PROJECT_NAME}
termcolor::termcolor
tclap::tclap
eCAL::play_core
eCAL::utils
)

if(MSVC)
Expand Down
20 changes: 20 additions & 0 deletions app/play/play_cli/src/ecal_play_cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
#include <iomanip>
#include <sstream>

#include <ecal_utils/str_convert.h>
#include <ecal_utils/command_line.h>

#ifdef WIN32
#define NOMINMAX
#endif // WIN32
Expand Down Expand Up @@ -208,7 +211,11 @@ void printMeasurementInformation(std::shared_ptr<EcalPlay> ecal_player)
}
}

#ifdef WIN32
int main()
#else
int main(int argc, char *argv[])
#endif // WIN32
{
TCLAP::CmdLine cmd("eCAL Player", ' ', EcalPlayGlobals::VERSION_STRING);

Expand Down Expand Up @@ -254,6 +261,17 @@ int main(int argc, char *argv[])
cmd.add(*arg_iterator);
}

#ifdef WIN32
auto utf8_argv_vector = EcalUtils::CommandLine::GetUtf8Argv();
try
{
cmd.parse(utf8_argv_vector);
}
catch (TCLAP::ArgException& e)
{
std::cerr << "Error parsing command line: " << e.what() << std::endl;
}
#else
try
{
cmd.parse(argc, argv);
Expand All @@ -262,6 +280,8 @@ int main(int argc, char *argv[])
{
std::cerr << "Error parsing command line: " << e.what() << std::endl;
}
#endif // WIN32


//////////////////////////////////////////////////////////////////////////////
//// Argument constraints ////
Expand Down
25 changes: 24 additions & 1 deletion app/play/play_core/src/ecal_play.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

#include <ecal_utils/string.h>
#include <ecal_utils/filesystem.h>
#include <ecal_utils/str_convert.h>

EcalPlay::EcalPlay()
{
Expand Down Expand Up @@ -151,7 +152,12 @@ std::map<std::string, std::string> EcalPlay::LoadChannelMappingFile(const std::s
{
std::map<std::string, std::string> channel_mapping;

#ifdef WIN32
std::wstring w_path = EcalUtils::StrConvert::Utf8ToWide(path);
std::ifstream mapping_file(w_path);
#else
std::ifstream mapping_file(path);
#endif // WIN32

if (mapping_file.is_open() == true)
{
Expand Down Expand Up @@ -199,8 +205,12 @@ bool EcalPlay::LoadDescription(const std::string& path)
std::stringstream ss;
std::string line;

#ifdef WIN32
std::wstring w_path = EcalUtils::StrConvert::Utf8ToWide(path);
std::ifstream description_file(w_path);
#else
std::ifstream description_file(path);

#endif // WIN32

if (description_file.is_open())
{
Expand Down Expand Up @@ -233,7 +243,13 @@ bool EcalPlay::LoadScenarios(const std::string& path)
scenarios_.clear();

std::string scenario_line;

#ifdef WIN32
std::wstring w_path = EcalUtils::StrConvert::Utf8ToWide(path);
std::ifstream scenario_file(w_path);
#else
std::ifstream scenario_file(path);
#endif // WIN32

if (scenario_file.is_open())
{
Expand Down Expand Up @@ -335,7 +351,14 @@ bool EcalPlay::SaveScenariosToDisk() const
}

std::ofstream scenario_file_stream;

#ifdef WIN32
std::wstring w_scenario_path = EcalUtils::StrConvert::Utf8ToWide(scenario_path);
scenario_file_stream.open (w_scenario_path);
#else
scenario_file_stream.open (scenario_path);
#endif // WIN32

if (!scenario_file_stream.is_open())
{
EcalPlayLogger::Instance()->error("Unable to save scenario.txt: Failed opening file \"" + scenario_path + "\"");
Expand Down
1 change: 1 addition & 0 deletions app/play/play_gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ target_link_libraries (${PROJECT_NAME}
eCAL::play_core
Qt5::Widgets
CustomQt
eCAL::utils
)
if (WIN32)
target_link_libraries (${PROJECT_NAME}
Expand Down
28 changes: 21 additions & 7 deletions app/play/play_gui/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
#include "help_window.h"
#include <ecal_play_logger.h>

#include <ecal_utils/str_convert.h>
#include <ecal_utils/command_line.h>

int main(int argc, char *argv[])
{
Expand All @@ -52,11 +54,11 @@ int main(int argc, char *argv[])
TCLAP::ValueArg<std::string> measurement_path_arg ("m", "measurement", "Loads the measurement from the path.", false, "", "Path");
TCLAP::SwitchArg play_arg ("p", "play", "Automatically starts the playback. Requires a measurement being loaded.", false);
TCLAP::ValueArg<std::string> channel_rename_file_path_arg ("c", "channel-mapping", "Loads the channel mapping from the given file and uses it to filter and intialize eCAL publishers. Otherwise, all publishers from the measurement will keep their default name.", false, "", "Path");
CustomTclap::FuzzyValueSwitchArgBool no_play_speed_limit_arg ("u", "unlimited-speed", "Publish frames as fast as possible", false, false, "true|false");
CustomTclap::FuzzyValueSwitchArgBool no_play_speed_limit_arg ("u", "unlimited-speed", "Publish frames as fast as possible", false, false, "true|false");
TCLAP::ValueArg<double> play_speed_arg ("s", "speed", "Relative rate at which the player shall publish the messages. Ignored, when using \"unlimited_play_speed\"", false, 1.0, "Factor");
CustomTclap::FuzzyValueSwitchArgBool allow_framedropping_arg ("f", "framedropping", "Drop frames when the messages cannot be sent at the required speed", false, false, "true|false");
CustomTclap::FuzzyValueSwitchArgBool enforce_delay_accuracy_arg ("d", "enforce-delay-accuracy", "Always wait the correct amount of time between two messages, even if this will slow down the playback", false, false, "true|false");
CustomTclap::FuzzyValueSwitchArgBool repeat_arg ("r", "repeat", "Repeat playback from the beginning if the end has been reached", false, false, "true|false");
CustomTclap::FuzzyValueSwitchArgBool allow_framedropping_arg ("f", "framedropping", "Drop frames when the messages cannot be sent at the required speed", false, false, "true|false");
CustomTclap::FuzzyValueSwitchArgBool enforce_delay_accuracy_arg ("d", "enforce-delay-accuracy", "Always wait the correct amount of time between two messages, even if this will slow down the playback", false, false, "true|false");
CustomTclap::FuzzyValueSwitchArgBool repeat_arg ("r", "repeat", "Repeat playback from the beginning if the end has been reached", false, false, "true|false");
TCLAP::ValueArg<double> limit_interval_start_arg ("l", "limit-interval-start", "Start the playback from this time (relative value in seconds, 0.0 indicates the begin of the measurement)", false, -1.0, "Seconds");
TCLAP::ValueArg<double> limit_interval_end_arg ("e", "limit-interval-end", "End the playback at this time (relative value in seconds)", false, -1.0, "Seconds");

Expand Down Expand Up @@ -88,6 +90,17 @@ int main(int argc, char *argv[])

cmd.setOutput(&advanced_tclap_output);

#ifdef WIN32
auto utf8_argv_vector = EcalUtils::CommandLine::GetUtf8Argv();
try
{
cmd.parse(utf8_argv_vector);
}
catch (TCLAP::ArgException& e)
{
std::cerr << "Error parsing command line: " << e.what() << std::endl;
}
#else
try
{
cmd.parse(argc, argv);
Expand All @@ -96,12 +109,13 @@ int main(int argc, char *argv[])
{
std::cerr << "Error parsing command line: " << e.what() << std::endl;
}
#endif // WIN32

QApplication a(argc, argv);

a.setOrganizationName("Continental");
a.setOrganizationDomain("continental-corporation.com");
a.setApplicationName("ecalplaygui");
a.setOrganizationName ("Continental");
a.setOrganizationDomain ("continental-corporation.com");
a.setApplicationName ("ecalplaygui");
a.setApplicationDisplayName("eCAL Player");

//////////////////////////////////////
Expand Down
11 changes: 10 additions & 1 deletion app/rec/rec_client_cli/src/ecal_rec_cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <ecal/msg/protobuf/server.h>

#include <ecal_utils/string.h>
#include <ecal_utils/command_line.h>

#include <tclap/CmdLine.h>

Expand Down Expand Up @@ -68,8 +69,11 @@ std::chrono::steady_clock::time_point ctrl_exit_until(std::chrono::steady_clock:
bool ctrl_exit_event(false);



#ifdef WIN32
int main()
#else
int main(int argc, char** argv)
#endif // WIN32
{
TCLAP::CmdLine cmd("eCAL Recorder", ' ', ECAL_REC_VERSION_STRING);

Expand Down Expand Up @@ -125,7 +129,12 @@ int main(int argc, char** argv)

try
{
#ifdef WIN32
auto utf8_args_vector = EcalUtils::CommandLine::GetUtf8Argv();
cmd.parse(utf8_args_vector);
#else
cmd.parse(argc, argv);
#endif // WIN32
}
catch (TCLAP::ArgException& e)
{
Expand Down
6 changes: 6 additions & 0 deletions app/rec/rec_client_core/src/job/ftp_upload_thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#endif

#include <ecal_utils/filesystem.h>
#include <ecal_utils/str_convert.h>

#ifdef WIN32
#define WIN32_LEAN_AND_MEAN
Expand Down Expand Up @@ -174,7 +175,12 @@ namespace eCAL

// Open the local file
std::ifstream file;
#ifdef WIN32
std::wstring w_native_path = EcalUtils::StrConvert::Utf8ToWide(EcalUtils::Filesystem::ToNativeSeperators(local_complete_file_path));
file.open(w_native_path, std::ios::binary);
#else
file.open(EcalUtils::Filesystem::ToNativeSeperators(local_complete_file_path), std::ios::binary);
#endif // WIN32

bool abort_uploading = false;

Expand Down
26 changes: 26 additions & 0 deletions app/rec/rec_client_core/src/job/record_job.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

#include "hdf5_writer_thread.h"

#include <ecal_utils/str_convert.h>

#ifdef ECAL_HAS_CURL
#include "ftp_upload_thread.h"
#endif // ECAL_HAS_CURL
Expand Down Expand Up @@ -140,7 +142,13 @@ namespace eCAL
std::string system_information_path = hostname_dir + "/system_information.txt";

std::ofstream system_information_file;
#ifdef WIN32
std::wstring w_system_information_path = EcalUtils::StrConvert::Utf8ToWide(system_information_path);
system_information_file.open(w_system_information_path, std::ios::trunc);
#else
system_information_file.open(system_information_path, std::ios::trunc);
#endif // WIN32

if (system_information_file.is_open())
{
std::string config_dump;
Expand Down Expand Up @@ -238,7 +246,13 @@ namespace eCAL
EcalRecLogger::Instance()->info("Creating eacalmeas file: " + ecalmeas_file_path);

std::ofstream ecalmeas_file;
#ifdef WIN32
std::wstring w_ecalmeas_file_path = EcalUtils::StrConvert::Utf8ToWide(ecalmeas_file_path);
ecalmeas_file.open(w_ecalmeas_file_path, std::ios::out | std::ios::trunc);
#else
ecalmeas_file.open(ecalmeas_file_path, std::ios::out | std::ios::trunc);
#endif // WIN32

if (ecalmeas_file.is_open())
{
ecalmeas_file.close();
Expand All @@ -261,7 +275,13 @@ namespace eCAL
EcalRecLogger::Instance()->info("Saving description to " + full_path);

std::ofstream description_file;
#ifdef WIN32
std::wstring w_full_path = EcalUtils::StrConvert::Utf8ToWide(full_path);
description_file.open(w_full_path, std::ios::out | std::ios::trunc);
#else
description_file.open(full_path, std::ios::out | std::ios::trunc);
#endif // WIN32

if (description_file.is_open())
{
description_file << job_config_.GetDescription();
Expand Down Expand Up @@ -452,7 +472,13 @@ namespace eCAL
if (!error)
{
std::ofstream description_file;
#ifdef WIN32
std::wstring w_description_path = EcalUtils::StrConvert::Utf8ToWide(description_path);
description_file.open(w_description_path, std::ios::out | std::ios::app);
#else
description_file.open(description_path, std::ios::out | std::ios::app);
#endif // WIN32

if (description_file.is_open())
{
description_file << std::endl;
Expand Down
7 changes: 7 additions & 0 deletions app/rec/rec_gui/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

#include <rec_client_core/ecal_rec_defs.h>

#include <ecal_utils/command_line.h>

#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable: 4505) // disable tclap warning (unreferenced local function has been removed)
Expand Down Expand Up @@ -83,7 +85,12 @@ int main(int argc, char *argv[])

try
{
#ifdef WIN32
auto utf8_args_vector = EcalUtils::CommandLine::GetUtf8Argv();
cmd.parse(utf8_args_vector);
#else
cmd.parse(argc, argv);
#endif // WIN32
}
catch (TCLAP::ArgException& e)
{
Expand Down
Loading

0 comments on commit 3e58c41

Please sign in to comment.