diff --git a/src/slic3r/GUI/PartPlate.cpp b/src/slic3r/GUI/PartPlate.cpp index b75afef0b..919f164dc 100644 --- a/src/slic3r/GUI/PartPlate.cpp +++ b/src/slic3r/GUI/PartPlate.cpp @@ -1,6 +1,5 @@ #include #include -#include #include #include #include @@ -1610,7 +1609,7 @@ void PartPlate::set_plate_name(const std::string &name) if (boost::equals(m_name, name)) return; m_name = name; - std::regex reg("[\\\\/:*?\"<>|]"); + std::regex reg("[\\\\/:*?\"<>|\\0]"); m_name= regex_replace(m_name, reg, ""); m_name_change = true; if (m_plater) { diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index f843b64fd..1a16ea24e 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -9474,7 +9474,7 @@ void Plater::export_gcode_3mf(bool export_all) //BBS replace gcode extension to .gcode.3mf default_output_file = default_output_file.replace_extension(".gcode.3mf"); - default_output_file = fs::path(Slic3r::fold_utf8_to_ascii(default_output_file.string())); + default_output_file = fs::path(Slic3r::fold_utf8_to_ascii(default_output_file.string(),true)); //Get a last save path start_dir = appconfig.get_last_output_dir(default_output_file.parent_path().string(), false); diff --git a/src/slic3r/Utils/ASCIIFolding.cpp b/src/slic3r/Utils/ASCIIFolding.cpp index 4bd902c6d..0eb02a5f8 100644 --- a/src/slic3r/Utils/ASCIIFolding.cpp +++ b/src/slic3r/Utils/ASCIIFolding.cpp @@ -4,6 +4,8 @@ #include #include #include +#include +#include namespace Slic3r { @@ -1942,7 +1944,7 @@ static void fold_to_ascii(wchar_t c, std::back_insert_iterator& ou *out = *it; } -std::string fold_utf8_to_ascii(const std::string &src) +std::string fold_utf8_to_ascii(const std::string &src, bool is_convert_for_filename) { std::wstring wstr = boost::locale::conv::utf_to_utf(src.c_str(), src.c_str() + src.size()); std::wstring dst; @@ -1950,6 +1952,21 @@ std::string fold_utf8_to_ascii(const std::string &src) auto out = std::back_insert_iterator(dst); for (wchar_t c : wstr) fold_to_ascii(c, out); + if (is_convert_for_filename) { + std::wstring_convert> converter; + auto dstStr = converter.to_bytes(dst); + + std::size_t found = dstStr.find_last_of("/\\"); + if (found != std::string::npos) { + std::string dir = dstStr.substr(0, found); + std::string filename = dstStr.substr(found + 1); + std::regex reg("[\\\\/:*?\"<>|\\0]"); + std::string newFileName = regex_replace(filename, reg, ""); + dstStr = dir + "\\" + newFileName; + } + dst = converter.from_bytes(dstStr); + } + return boost::locale::conv::utf_to_utf(dst.c_str(), dst.c_str() + dst.size()); } diff --git a/src/slic3r/Utils/ASCIIFolding.hpp b/src/slic3r/Utils/ASCIIFolding.hpp index 0a4aff3da..9fde55c5a 100644 --- a/src/slic3r/Utils/ASCIIFolding.hpp +++ b/src/slic3r/Utils/ASCIIFolding.hpp @@ -7,7 +7,7 @@ namespace Slic3r { // If possible, remove accents from accented latin characters. // This function is useful for generating file names to be processed by legacy firmwares. -extern std::string fold_utf8_to_ascii(const std::string &src); +extern std::string fold_utf8_to_ascii(const std::string &src,bool is_convert_for_filename=false); // Convert the input UNICODE character to a string of maximum 4 output ASCII characters. // Return the end of the string written to the output.