From a475e3573037f1bcd3ddb65c1ce09436a13b8fa9 Mon Sep 17 00:00:00 2001 From: SoftFever Date: Mon, 30 Mar 2026 14:51:45 +0800 Subject: [PATCH] Fix non-ASCII path corruption on Windows using from_path() helper (#13036) --- src/slic3r/GUI/GUI_App.cpp | 15 +++++++-------- src/slic3r/GUI/HMS.cpp | 3 ++- src/slic3r/GUI/Plater.cpp | 4 ++-- src/slic3r/GUI/SendToPrinter.cpp | 2 +- src/slic3r/GUI/WipeTowerDialog.cpp | 2 +- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index 8fd8dd30a0..b0c0bef473 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -7949,11 +7949,12 @@ bool GUI_App::check_url_association(std::wstring url_prefix, std::wstring& reg_b if (!key_full.Exists()) { return false; } - reg_bin = key_full.QueryDefaultValue().ToStdWstring(); + wxString reg_value = key_full.QueryDefaultValue(); + reg_bin = reg_value.ToStdWstring(); boost::filesystem::path binary_path(boost::filesystem::canonical(boost::dll::program_location())); - std::wstring key_string = L"\"" + binary_path.wstring() + L"\" \"%1\""; - return key_string == reg_bin; + wxString key_string = "\"" + from_path(binary_path) + "\" \"%1\""; + return key_string == reg_value; #else return false; #endif // WIN32 @@ -7963,12 +7964,10 @@ void GUI_App::associate_url(std::wstring url_prefix) { #ifdef WIN32 boost::filesystem::path binary_path(boost::filesystem::canonical(boost::dll::program_location())); - // the path to binary needs to be correctly saved in string with respect to localized characters - wxString wbinary = wxString::FromUTF8(binary_path.string()); - std::string binary_string = (boost::format("%1%") % wbinary).str(); - BOOST_LOG_TRIVIAL(info) << "Downloader registration: Path of binary: " << binary_string; + wxString wbinary = from_path(binary_path); + BOOST_LOG_TRIVIAL(info) << "Downloader registration: Path of binary: " << wbinary.ToUTF8().data(); - std::string key_string = "\"" + binary_string + "\" \"%1\""; + wxString key_string = "\"" + wbinary + "\" \"%1\""; wxRegKey key_first(wxRegKey::HKCU, "Software\\Classes\\" + url_prefix); wxRegKey key_full(wxRegKey::HKCU, "Software\\Classes\\" + url_prefix + "\\shell\\open\\command"); diff --git a/src/slic3r/GUI/HMS.cpp b/src/slic3r/GUI/HMS.cpp index 6f242f7871..e940046d52 100644 --- a/src/slic3r/GUI/HMS.cpp +++ b/src/slic3r/GUI/HMS.cpp @@ -1,5 +1,6 @@ #include "HMS.hpp" +#include "GUI.hpp" #include "DeviceManager.hpp" #include "DeviceCore/DevManager.h" #include "DeviceCore/DevUtil.h" @@ -567,7 +568,7 @@ wxImage HMSQuery::query_image_from_local(const wxString& image_name) { const fs::path& image_path = entry.path(); const fs::path& image_name = fs::relative(image_path, local_img_dir); - m_hms_local_images[image_name.string()] = wxImage(wxString::FromUTF8(image_path.string())); + m_hms_local_images[from_path(image_name)] = wxImage(from_path(image_path)); } } } diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index c26215936e..ef46801722 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -12112,9 +12112,9 @@ void Plater::import_model_id(wxString download_info) /* load project */ // Orca: If download is a zip file, treat it as if file has been drag and dropped on the plater if (target_path.extension() == ".zip") - { wxArrayString arr; arr.Add(wxString::FromUTF8(target_path.string())); this->load_files(arr); } + { wxArrayString arr; arr.Add(from_path(target_path)); this->load_files(arr); } else - this->load_project(target_path.wstring()); + this->load_project(from_path(target_path)); /*BBS set project info after load project, project info is reset in load project */ //p->project.project_model_id = model_id; //p->project.project_design_id = design_id; diff --git a/src/slic3r/GUI/SendToPrinter.cpp b/src/slic3r/GUI/SendToPrinter.cpp index 1cc0e66b76..69482b623d 100644 --- a/src/slic3r/GUI/SendToPrinter.cpp +++ b/src/slic3r/GUI/SendToPrinter.cpp @@ -1541,7 +1541,7 @@ void SendToPrinterDialog::set_default() } fs::path filename_path(filename.c_str()); - m_current_project_name = wxString::FromUTF8(filename_path.filename().string()); + m_current_project_name = from_path(filename_path.filename()); //unsupported character filter m_current_project_name = from_u8(filter_characters(m_current_project_name.ToUTF8().data(), "<>[]:/\\|?*\"")); diff --git a/src/slic3r/GUI/WipeTowerDialog.cpp b/src/slic3r/GUI/WipeTowerDialog.cpp index 88c4b27309..fef5520eb0 100644 --- a/src/slic3r/GUI/WipeTowerDialog.cpp +++ b/src/slic3r/GUI/WipeTowerDialog.cpp @@ -404,7 +404,7 @@ WipingDialog::WipingDialog(wxWindow* parent, const int max_flush_volume) : main_sizer->Add(m_webview, 1, wxEXPAND); fs::path filepath = fs::path(resources_dir()) / "web/flush/WipingDialog.html"; - wxString filepath_str = wxString::FromUTF8(filepath.string()); + wxString filepath_str = from_path(filepath); wxFileName fn(filepath_str); if(fn.FileExists()) { wxString url = wxFileSystem::FileNameToURL(fn);