mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-08 07:27:41 -06:00
ENH:importing to studio will retry three times
jira:[STUDIO-4223] Change-Id: If66faa4a21a414d43860ef8aa657562f5ee617b8 (cherry picked from commit 59ca516ba5b8ada15cbb087a814f59f8e3683a51)
This commit is contained in:
parent
fab4045723
commit
7aba8e5e88
1 changed files with 41 additions and 30 deletions
|
@ -8011,7 +8011,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);
|
||||||
|
@ -8039,7 +8040,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;
|
||||||
|
@ -8110,6 +8111,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) {
|
||||||
|
@ -8117,15 +8121,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);
|
||||||
|
@ -8134,11 +8140,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) {
|
||||||
|
@ -8176,7 +8183,11 @@ void Plater::import_model_id(wxString download_info)
|
||||||
p->notification_manager->push_import_finished_notification(target_path.string(), target_path.parent_path().string(), false);
|
p->notification_manager->push_import_finished_notification(target_path.string(), target_path.parent_path().string(), false);
|
||||||
}
|
}
|
||||||
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…
Add table
Add a link
Reference in a new issue