mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-11 16:57:53 -06:00
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.
This commit is contained in:
parent
1bf67b4b62
commit
f5160b7a72
5 changed files with 113 additions and 6 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue