ENH:rename model file after download finish

Change-Id: I3ae1c8ca4f53bf41c00688b6bb5b0c0e0a4f869b
This commit is contained in:
tao wang 2023-04-20 12:45:26 +08:00 committed by Lane.Wei
parent 2dbd2bcef9
commit 8ceb0e6b7b
3 changed files with 33 additions and 16 deletions

View file

@ -977,7 +977,7 @@ static void generic_exception_handle()
//#endif
}
static std::vector<std::string> split_str(const std::string& src, const std::string& separator)
std::vector<std::string> GUI_App::split_str(const std::string& src, const std::string& separator)
{
size_t pos;
size_t start_pos = 0;
@ -997,6 +997,7 @@ void GUI_App::post_init()
if (! this->initialized())
throw Slic3r::RuntimeError("Calling post_init() while not yet initialized");
bool switch_to_3d = false;
if (!this->init_params->input_files.empty()) {
@ -1004,21 +1005,19 @@ void GUI_App::post_init()
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", init with input files, size %1%, input_gcode %2%")
%this->init_params->input_files.size() %this->init_params->input_gcode;
if (this->init_params->input_files.size() == 1 &&
boost::starts_with(this->init_params->input_files.front(), "bambustudio://open")) {
auto input_str_arr = split_str(this->init_params->input_files.front(), "bambustudio://open/?file=");
std::string download_origin_url;
std::string download_params_url = url_decode(this->init_params->input_files.front());
auto input_str_arr = split_str(download_params_url, "bambustudio://open?file=");
std::string download_url;
for (auto input_str : input_str_arr) {
if (!input_str.empty()) download_origin_url = input_str;
if (!input_str.empty()) download_url = input_str;
}
std::string download_file_url = url_decode(download_origin_url);
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << download_file_url;
if (!download_file_url.empty() && ( boost::starts_with(download_file_url, "http://") || boost::starts_with(download_file_url, "https://")) ) {
request_model_download(download_origin_url);
if (!download_url.empty() && ( boost::starts_with(download_url, "http://") || boost::starts_with(download_url, "https://")) ) {
request_model_download(download_url);
}
}
else {

View file

@ -314,6 +314,7 @@ public:
bool is_recreating_gui() const { return m_is_recreating_gui; }
std::string logo_name() const { return is_editor() ? "BambuStudio" : "BambuStudio-gcodeviewer"; }
std::vector<std::string> split_str(const std::string& src, const std::string& separator);
// To be called after the GUI is fully built up.
// Process command line parameters cached in this->init_params,
// load configs, STLs etc.

View file

@ -7776,14 +7776,31 @@ int Plater::save_project(bool saveAs)
//BBS import model by model id
void Plater::import_model_id(const std::string& download_info)
{
std::string download_origin_url = wxGetApp().url_decode(download_info);
std::string download_url;
std::string filename;
std::string download_origin_url = wxGetApp().url_decode(download_info);
try
{
std::vector<std::string> origin_array = wxGetApp().split_str(download_origin_url, "&name=");
if (origin_array.size() >= 2) {
download_url = origin_array[0];
filename = origin_array[1];
}
else if (!download_origin_url.empty()) {
fs::path download_path = fs::path(download_origin_url);
download_url = download_origin_url;
filename = download_path.filename().string();
}
}
catch (const std::exception& error)
{
//wxString sError = error.what();
}
bool download_ok = false;
/* save to a file */