From 1c4ed26b81ae9308ee66355f072a405c3d38e092 Mon Sep 17 00:00:00 2001 From: tao wang Date: Mon, 31 Oct 2022 19:54:23 +0800 Subject: [PATCH] FIX:fixed crash caused by unable to resolve file name Change-Id: I98388cd95e8b2bc26d33cddcc4945580a1c34292 --- src/slic3r/GUI/GUI_App.cpp | 10 +++++++--- src/slic3r/GUI/GUI_App.hpp | 2 +- src/slic3r/GUI/ModelMall.cpp | 6 +++++- src/slic3r/GUI/Plater.cpp | 31 ++++++++++++++++--------------- src/slic3r/GUI/Plater.hpp | 4 ++-- 5 files changed, 31 insertions(+), 22 deletions(-) diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index a5f861aad..0d421d333 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -3216,7 +3216,11 @@ std::string GUI_App::handle_web_request(std::string cmd) if (j["data"].contains("download_url")) download_url = j["data"]["download_url"].get(); - this->request_model_download(download_url); + std::string filename = ""; + if (j["data"].contains("filename")) + download_url = j["data"]["filename"].get(); + + this->request_model_download(download_url, filename); } std::stringstream ss(cmd), oss; @@ -3388,12 +3392,12 @@ void GUI_App::handle_script_message(std::string msg) } } -void GUI_App::request_model_download(std::string import_json) +void GUI_App::request_model_download(std::string url, std::string filename) { if (!check_login()) return; if (plater_) { - plater_->request_model_download(import_json); + plater_->request_model_download(url, filename); } } diff --git a/src/slic3r/GUI/GUI_App.hpp b/src/slic3r/GUI/GUI_App.hpp index 9cbb79717..a278d2bf1 100644 --- a/src/slic3r/GUI/GUI_App.hpp +++ b/src/slic3r/GUI/GUI_App.hpp @@ -376,7 +376,7 @@ public: int request_user_unbind(std::string dev_id); std::string handle_web_request(std::string cmd); void handle_script_message(std::string msg); - void request_model_download(std::string import_json); + void request_model_download(std::string url, std::string filename); void download_project(std::string project_id); void request_project_download(std::string project_id); void request_open_project(std::string project_id); diff --git a/src/slic3r/GUI/ModelMall.cpp b/src/slic3r/GUI/ModelMall.cpp index 34528ca07..06a6ae479 100644 --- a/src/slic3r/GUI/ModelMall.cpp +++ b/src/slic3r/GUI/ModelMall.cpp @@ -129,8 +129,12 @@ namespace GUI { if (j["data"].contains("download_url")) download_url = j["data"]["download_url"].get(); + std::string filename = ""; + if (j["data"].contains("filename")) + download_url = j["data"]["filename"].get(); + if (download_url.empty()) return; - wxGetApp().plater()->request_model_download(download_url); + wxGetApp().plater()->request_model_download(download_url, filename); } } diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index ac31e3e99..b8977aa4e 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -7155,12 +7155,17 @@ int Plater::save_project(bool saveAs) } //BBS import model by model id -void Plater::import_model_id(const std::string& download_url) +void Plater::import_model_id(const std::string& download_info) { - /* json j; - std::string model_id = ""; - std::string profile_id = ""; - std::string design_id;*/ + std::string download_url = ""; + wxString filename = ""; + + auto selection_data_arr = wxSplit(download_info, '|'); + + if (selection_data_arr.size() == 2) { + download_url = selection_data_arr[0].ToStdString(); + filename = selection_data_arr[1].ToStdString(); + } bool download_ok = false; @@ -7175,7 +7180,7 @@ void Plater::import_model_id(const std::string& download_url) bool cancel = false; wxString msg; wxString dlg_title = _L("Importing Model"); - wxString filename; + int percent = 1; ProgressDialog dlg(dlg_title, wxString(' ', 100) + "\n\n\n\n", @@ -7212,8 +7217,6 @@ void Plater::import_model_id(const std::string& download_url) return; }*/ //filename = from_u8(profile->filename); - - //filename = from_u8(fs::path(download_url).filename().string()); //gets the number of files with the same name @@ -7222,7 +7225,7 @@ void Plater::import_model_id(const std::string& download_url) target_path = fs::path(wxGetApp().app_config->get("download_path")); - filename = from_u8(fs::path(download_url).filename().string()); + //filename = from_u8(fs::path(download_url).filename().string()); try { @@ -7248,13 +7251,11 @@ void Plater::import_model_id(const std::string& download_url) //update filename if (is_already_exist && vecFiles.size() >= 1) { - wxString extension = fs::path(download_url).extension().c_str(); + wxString extension = fs::path(filename).extension().c_str(); wxString name = filename.SubString(0, filename.length() - extension.length() - 1); filename = wxString::Format("%s(%d)%s",name, vecFiles.size() + 1, extension); } - else { - filename = from_u8(fs::path(download_url).filename().string()); - } + msg = _L("downloading project ..."); @@ -7347,10 +7348,10 @@ void Plater::download_project(const wxString& project_id) return; } -void Plater::request_model_download(std::string import_json) +void Plater::request_model_download(std::string url, std::string filename) { wxCommandEvent* event = new wxCommandEvent(EVT_IMPORT_MODEL_ID); - event->SetString(wxString(import_json)); + event->SetString(wxString::Format("%s|%s", wxString(url), wxString(filename))); wxQueueEvent(this, event); } diff --git a/src/slic3r/GUI/Plater.hpp b/src/slic3r/GUI/Plater.hpp index 91c5d26fc..a176e1daa 100644 --- a/src/slic3r/GUI/Plater.hpp +++ b/src/slic3r/GUI/Plater.hpp @@ -202,9 +202,9 @@ public: void load_project(wxString const & filename = "", wxString const & originfile = "-"); int save_project(bool saveAs = false); //BBS download project by project id - void import_model_id(const std::string& download_url); + void import_model_id(const std::string& download_info); void download_project(const wxString& project_id); - void request_model_download(std::string import_json); + void request_model_download(std::string url, std::string filename); void request_download_project(std::string project_id); // BBS: check snapshot bool up_to_date(bool saved, bool backup);