Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/prusa3d/PrusaSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbubnikv <bubnikv@gmail.com>2017-12-21 18:56:33 +0300
committerbubnikv <bubnikv@gmail.com>2017-12-21 18:56:33 +0300
commitf5160b7a72dcb9305e6220a88092e3bd1032387e (patch)
treeb899493a87377c4ae9de17e3b68be150f5ce62f5 /xs/src/libslic3r/utils.cpp
parent1bf67b4b62c09d06eefab368b8698c291f05afde (diff)
Fixed "Slic3r crashes when sending STLs with special characters to the printer"
https://github.com/prusa3d/Slic3r/issues/597 The "Send to OctoPrint" function will now send the file name encoded in UTF-8, so the file name will not get mangled. The C++ Slic3r::encode_path() function was returning a string to Perl, which was marked as UTF-8. This has been fixed, now encode_path() returns a plain Perl string. Added path_to_filename, path_to_stem, path_to_extension, path_to_parent_path Perl wrappers to boost::filesystem::path splitting functionality to be able to split UTF-8 encoded files on Windows correctly.
Diffstat (limited to 'xs/src/libslic3r/utils.cpp')
-rw-r--r--xs/src/libslic3r/utils.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/xs/src/libslic3r/utils.cpp b/xs/src/libslic3r/utils.cpp
index ef05dcae7..1a7e16f11 100644
--- a/xs/src/libslic3r/utils.cpp
+++ b/xs/src/libslic3r/utils.cpp
@@ -10,6 +10,8 @@
#include <boost/algorithm/string/predicate.hpp>
#include <boost/date_time/local_time/local_time.hpp>
#include <boost/filesystem.hpp>
+#include <boost/filesystem/path.hpp>
+#include <boost/nowide/fstream.hpp>
#include <boost/nowide/integration/filesystem.hpp>
#include <boost/nowide/convert.hpp>
@@ -235,6 +237,17 @@ std::string normalize_utf8_nfc(const char *src)
return boost::locale::normalize(src, boost::locale::norm_nfc, locale_utf8);
}
+namespace PerlUtils {
+ // Get a file name including the extension.
+ std::string path_to_filename(const char *src) { return boost::filesystem::path(src).filename().string(); }
+ // Get a file name without the extension.
+ std::string path_to_stem(const char *src) { return boost::filesystem::path(src).stem().string(); }
+ // Get just the extension.
+ std::string path_to_extension(const char *src) { return boost::filesystem::path(src).extension().string(); }
+ // Get a directory without the trailing slash.
+ std::string path_to_parent_path(const char *src) { return boost::filesystem::path(src).parent_path().string(); }
+};
+
std::string timestamp_str()
{
const auto now = boost::posix_time::second_clock::local_time();
@@ -247,4 +260,31 @@ std::string timestamp_str()
return buf;
}
+std::string octoprint_encode_file_send_request_content(const char *cpath, bool select, bool print, const char *boundary)
+{
+ // Read the complete G-code string into a string buffer.
+ // It will throw if the file cannot be open or read.
+ std::stringstream str_stream;
+ {
+ boost::nowide::ifstream ifs(cpath);
+ str_stream << ifs.rdbuf();
+ }
+
+ boost::filesystem::path path(cpath);
+ std::string request = boundary + '\n';
+ request += "Content-Disposition: form-data; name=\"";
+ request += path.stem().string() + "\"; filename=\"" + path.filename().string() + "\"\n";
+ request += "Content-Type: application/octet-stream\n\n";
+ request += str_stream.str();
+ request += boundary + '\n';
+ request += "Content-Disposition: form-data; name=\"select\"\n\n";
+ request += select ? "true\n" : "false\n";
+ request += boundary + '\n';
+ request += "Content-Disposition: form-data; name=\"print\"\n\n";
+ request += print ? "true\n" : "false\n";
+ request += boundary + '\n';
+
+ return request;
+}
+
}; // namespace Slic3r