ENH:importing to studio will retry three times
jira:[STUDIO-4223] Change-Id: If66faa4a21a414d43860ef8aa657562f5ee617b8
This commit is contained in:
parent
ef6ce95341
commit
e171425b3e
|
@ -8175,7 +8175,8 @@ void Plater::import_model_id(wxString download_info)
|
||||||
}
|
}
|
||||||
|
|
||||||
bool download_ok = false;
|
bool download_ok = false;
|
||||||
/* save to a file */
|
int retry_count = 0;
|
||||||
|
const int max_retries = 3;
|
||||||
|
|
||||||
/* jump to 3D eidtor */
|
/* jump to 3D eidtor */
|
||||||
wxGetApp().mainframe->select_tab((size_t)MainFrame::TabPosition::tp3DEditor);
|
wxGetApp().mainframe->select_tab((size_t)MainFrame::TabPosition::tp3DEditor);
|
||||||
|
@ -8203,7 +8204,7 @@ void Plater::import_model_id(wxString download_info)
|
||||||
p->project.reset();
|
p->project.reset();
|
||||||
|
|
||||||
/* prepare project and profile */
|
/* prepare project and profile */
|
||||||
boost::thread import_thread = Slic3r::create_thread([&percent, &cont, &cancel, &msg, &target_path, &download_ok, download_url, &filename] {
|
boost::thread import_thread = Slic3r::create_thread([&percent, &cont, &cancel, &retry_count, max_retries, &msg, &target_path, &download_ok, download_url, &filename] {
|
||||||
|
|
||||||
NetworkAgent* m_agent = Slic3r::GUI::wxGetApp().getAgent();
|
NetworkAgent* m_agent = Slic3r::GUI::wxGetApp().getAgent();
|
||||||
if (!m_agent) return;
|
if (!m_agent) return;
|
||||||
|
@ -8274,6 +8275,9 @@ void Plater::import_model_id(wxString download_info)
|
||||||
|
|
||||||
auto url = download_url;
|
auto url = download_url;
|
||||||
auto http = Http::get(url);
|
auto http = Http::get(url);
|
||||||
|
|
||||||
|
while (cont && retry_count < max_retries) {
|
||||||
|
retry_count++;
|
||||||
http.on_progress([&percent, &cont, &msg](Http::Progress progress, bool& cancel) {
|
http.on_progress([&percent, &cont, &msg](Http::Progress progress, bool& cancel) {
|
||||||
if (!cont) cancel = true;
|
if (!cont) cancel = true;
|
||||||
if (progress.dltotal != 0) {
|
if (progress.dltotal != 0) {
|
||||||
|
@ -8281,15 +8285,17 @@ void Plater::import_model_id(wxString download_info)
|
||||||
}
|
}
|
||||||
msg = wxString::Format(_L("Project downloaded %d%%"), percent);
|
msg = wxString::Format(_L("Project downloaded %d%%"), percent);
|
||||||
})
|
})
|
||||||
.on_error([&msg, &cont](std::string body, std::string error, unsigned http_status) {
|
.on_error([&msg, &cont, &retry_count, max_retries](std::string body, std::string error, unsigned http_status) {
|
||||||
(void)body;
|
(void)body;
|
||||||
BOOST_LOG_TRIVIAL(error) << format("Error getting: `%1%`: HTTP %2%, %3%",
|
BOOST_LOG_TRIVIAL(error) << format("Error getting: `%1%`: HTTP %2%, %3%",
|
||||||
body,
|
body,
|
||||||
http_status,
|
http_status,
|
||||||
error);
|
error);
|
||||||
msg = wxString::Format("Download Failed! body=%s, error=%s, status=%d", body, error, http_status);
|
|
||||||
|
if (retry_count == max_retries) {
|
||||||
|
msg = _L("Importing to Bambu Studio failed. Please download the file and manually import it.");
|
||||||
cont = false;
|
cont = false;
|
||||||
return;
|
}
|
||||||
})
|
})
|
||||||
.on_complete([&cont, &download_ok, tmp_path, target_path](std::string body, unsigned /* http_status */) {
|
.on_complete([&cont, &download_ok, tmp_path, target_path](std::string body, unsigned /* http_status */) {
|
||||||
fs::fstream file(tmp_path, std::ios::out | std::ios::binary | std::ios::trunc);
|
fs::fstream file(tmp_path, std::ios::out | std::ios::binary | std::ios::trunc);
|
||||||
|
@ -8298,11 +8304,12 @@ void Plater::import_model_id(wxString download_info)
|
||||||
fs::rename(tmp_path, target_path);
|
fs::rename(tmp_path, target_path);
|
||||||
cont = false;
|
cont = false;
|
||||||
download_ok = true;
|
download_ok = true;
|
||||||
})
|
}).perform_sync();
|
||||||
.perform_sync();
|
|
||||||
|
|
||||||
// for break while
|
// for break while
|
||||||
cont = false;
|
//cont = false;
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
while (cont && cont_dlg) {
|
while (cont && cont_dlg) {
|
||||||
|
@ -8339,7 +8346,11 @@ void Plater::import_model_id(wxString download_info)
|
||||||
p->set_project_filename(wxString(filename));
|
p->set_project_filename(wxString(filename));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (!msg.empty()) wxMessageBox(msg);
|
if (!msg.empty()) {
|
||||||
|
MessageDialog msg_wingow(nullptr, msg, wxEmptyString, wxICON_WARNING | wxOK);
|
||||||
|
msg_wingow.SetSize(wxSize(FromDIP(480), -1));
|
||||||
|
msg_wingow.ShowModal();
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue