diff --git a/lib/Slic3r/Config.pm b/lib/Slic3r/Config.pm index 0ba05cf23e..52d67bfee5 100644 --- a/lib/Slic3r/Config.pm +++ b/lib/Slic3r/Config.pm @@ -95,6 +95,7 @@ sub load { # legacy syntax of load() my $config = $class->new; + $config->_load($file); return $config; } diff --git a/xs/src/libslic3r/Config.cpp b/xs/src/libslic3r/Config.cpp index 51a24c055f..da33b2fcd1 100644 --- a/xs/src/libslic3r/Config.cpp +++ b/xs/src/libslic3r/Config.cpp @@ -10,9 +10,11 @@ #include #include #include +#include #include #include #include +#include #include #include #include @@ -387,7 +389,8 @@ ConfigBase::load(const std::string &file) { namespace pt = boost::property_tree; pt::ptree tree; - pt::read_ini(file, tree); + boost::nowide::ifstream ifs(file); + pt::read_ini(ifs, tree); BOOST_FOREACH(const pt::ptree::value_type &v, tree) { try { t_config_option_key opt_key = v.first; @@ -403,8 +406,8 @@ void ConfigBase::save(const std::string &file) const { using namespace std; - ofstream c; - c.open(file.c_str(), ios::out | ios::trunc); + boost::nowide::ofstream c; + c.open(file, ios::out | ios::trunc); { time_t now; diff --git a/xs/src/libslic3r/IO.cpp b/xs/src/libslic3r/IO.cpp index bdb892373b..5b7c77d2da 100644 --- a/xs/src/libslic3r/IO.cpp +++ b/xs/src/libslic3r/IO.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #define TINYOBJLOADER_IMPLEMENTATION #include "tiny_obj_loader.h" @@ -12,7 +13,6 @@ namespace Slic3r { namespace IO { bool STL::read(std::string input_file, TriangleMesh* mesh) { - // TODO: encode file name // TODO: check that file exists try { @@ -81,7 +81,8 @@ OBJ::read(std::string input_file, Model* model) std::vector shapes; std::vector materials; std::string err; - bool ret = tinyobj::LoadObj(&attrib, &shapes, &materials, &err, input_file.c_str()); + boost::nowide::ifstream ifs(input_file); + bool ret = tinyobj::LoadObj(&attrib, &shapes, &materials, &err, &ifs); if (!err.empty()) { // `err` may contain warning message. std::cerr << err << std::endl; @@ -153,7 +154,7 @@ POV::write(TriangleMesh& mesh, std::string output_file) mesh2.center_around_origin(); using namespace std; - ofstream pov; + boost::nowide::ofstream pov; pov.open(output_file.c_str(), ios::out | ios::trunc); for (int i = 0; i < mesh2.stl.stats.number_of_facets; ++i) { const stl_facet &f = mesh2.stl.facet_start[i]; diff --git a/xs/src/libslic3r/IO/AMF.cpp b/xs/src/libslic3r/IO/AMF.cpp index f0f1c8853a..7433762ee9 100644 --- a/xs/src/libslic3r/IO/AMF.cpp +++ b/xs/src/libslic3r/IO/AMF.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -455,7 +456,7 @@ AMF::read(std::string input_file, Model* model) return false; } - std::fstream fin(input_file.c_str(), std::ios::in); + boost::nowide::ifstream fin(input_file, std::ios::in); if (!fin.is_open()) { boost::nowide::cerr << "Cannot open file: " << input_file << std::endl; return false; @@ -468,8 +469,9 @@ AMF::read(std::string input_file, Model* model) char buff[8192]; bool result = false; - while (fin.read(buff, sizeof(buff))) { - if (fin.fail()) { + while (!fin.eof()) { + fin.read(buff, sizeof(buff)); + if (fin.bad()) { printf("AMF parser: Read error\n"); break; } @@ -498,12 +500,12 @@ AMF::write(Model& model, std::string output_file) { using namespace std; - ofstream file; + boost::nowide::ofstream file; file.open(output_file, ios::out | ios::trunc); file << "" << endl << "" << endl - << "Slic3r " << SLIC3R_VERSION << "" << endl; + << " Slic3r " << SLIC3R_VERSION << "" << endl; for (const auto &material : model.materials) { if (material.first.empty()) @@ -597,7 +599,7 @@ AMF::write(Model& model, std::string output_file) << " " << endl << " " << instance->offset.x + object->origin_translation.x << "" << endl << " " << instance->offset.y + object->origin_translation.y << "" << endl - << " %" << instance->rotation << "" << endl + << " " << instance->rotation << "" << endl << " " << instance->scaling_factor << "" << endl << " " << endl; }