From e79eac2671fca060a04d8183e97b655523eafdfb Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sun, 28 Aug 2016 10:43:00 +0200 Subject: [PATCH] More fixes for non-ASCII paths on Windows --- .travis.yml | 1 + xs/Build.PL | 2 +- xs/src/libslic3r/Config.cpp | 27 +++++++++++++++++++++------ 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index f25d6bcbdb..a9cd3167ff 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,3 +20,4 @@ addons: - libboost-thread1.55-dev - libboost-system1.55-dev - libboost-filesystem1.55-dev + - libboost-locale1.55-dev diff --git a/xs/Build.PL b/xs/Build.PL index 8a111c1a44..6d4342bf1d 100644 --- a/xs/Build.PL +++ b/xs/Build.PL @@ -47,7 +47,7 @@ if (defined $ENV{BOOST_DIR}) { # In order to generate the -l switches we need to know how Boost libraries are named my $have_boost = 0; -my @boost_libraries = qw(system thread filesystem); # we need these +my @boost_libraries = qw(system thread filesystem locale); # we need these # check without explicit lib path (works on Linux) $have_boost = 1 diff --git a/xs/src/libslic3r/Config.cpp b/xs/src/libslic3r/Config.cpp index 372b7b1b03..b76550a092 100644 --- a/xs/src/libslic3r/Config.cpp +++ b/xs/src/libslic3r/Config.cpp @@ -4,10 +4,14 @@ #include #include #include +#include #include // std::runtime_error #include #include +#include +#include #include +#include #include #include @@ -214,21 +218,32 @@ ConfigBase::load(const std::string &file) void ConfigBase::save(const std::string &file) const { - using namespace std; - ofstream c; - c.open(file.c_str(), ios::out | ios::trunc); + // Get the default locale + std::locale loc = boost::locale::generator().generate(""); + // Set the global locale to loc + std::locale::global(loc); + + // Make boost.filesystem use it by default + boost::filesystem::path::imbue(std::locale()); + + // Create the path (file is assumed to be be utf-8) + boost::filesystem::path path(file); + + boost::filesystem::ofstream c; + c.open(path, std::ios::out | std::ios::trunc); + { time_t now; time(&now); char buf[sizeof "0000-00-00 00:00:00"]; strftime(buf, sizeof buf, "%F %T", gmtime(&now)); - c << "# generated by Slic3r " << SLIC3R_VERSION << " on " << buf << endl; + c << "# generated by Slic3r " << SLIC3R_VERSION << " on " << buf << std::endl; } - + t_config_option_keys my_keys = this->keys(); for (t_config_option_keys::const_iterator opt_key = my_keys.begin(); opt_key != my_keys.end(); ++opt_key) - c << *opt_key << " = " << this->serialize(*opt_key) << endl; + c << *opt_key << " = " << this->serialize(*opt_key) << std::endl; c.close(); }