FIX: [STUDIO-2964] something with fix printer file management

Change-Id: Id8c2349766c8ca3f90a0985873726a72f760da50
This commit is contained in:
chunmao.guo 2023-05-23 15:28:33 +08:00 committed by Lane.Wei
parent f5960411a3
commit e48170e7fe
3 changed files with 29 additions and 13 deletions

View file

@ -638,6 +638,7 @@ void Slic3r::GUI::ImageGrid::renderContent2(wxDC &dc, wxPoint const &pt, int ind
// Draw thumbnail & buttons // Draw thumbnail & buttons
int h = m_content_rect.GetHeight() * 64 / 264; int h = m_content_rect.GetHeight() * 64 / 264;
m_content_rect.SetHeight(m_content_rect.GetHeight() - h); m_content_rect.SetHeight(m_content_rect.GetHeight() - h);
dc.DrawRectangle(pt, m_content_rect.GetSize()); // Fix translucent model thumbnail
renderContent1(dc, pt, index, hit); renderContent1(dc, pt, index, hit);
m_content_rect.SetHeight(m_content_rect.GetHeight() + h); m_content_rect.SetHeight(m_content_rect.GetHeight() + h);
// Draw info bar // Draw info bar

View file

@ -267,12 +267,13 @@ void MediaFilePanel::SetMachineObject(MachineObject* obj)
ScalableBitmap icon; ScalableBitmap icon;
wxString msg; wxString msg;
int status = e.GetInt(); int status = e.GetInt();
int extra = e.GetExtraLong();
switch (status) { switch (status) {
case PrinterFileSystem::Initializing: icon = m_bmp_loading; msg = _L("Initializing..."); break; case PrinterFileSystem::Initializing: icon = m_bmp_loading; msg = _L("Initializing..."); break;
case PrinterFileSystem::Connecting: icon = m_bmp_loading; msg = _L("Connecting..."); break; case PrinterFileSystem::Connecting: icon = m_bmp_loading; msg = _L("Connecting..."); break;
case PrinterFileSystem::Failed: icon = m_bmp_failed; if (e.GetExtraLong() != 1) msg = _L("Connect failed [%d]!"); break; case PrinterFileSystem::Failed: icon = m_bmp_failed; if (extra != 1) msg = _L("Connect failed [%d]!"); break;
case PrinterFileSystem::ListSyncing: icon = m_bmp_loading; msg = _L("Loading file list..."); break; case PrinterFileSystem::ListSyncing: icon = m_bmp_loading; msg = _L("Loading file list..."); break;
case PrinterFileSystem::ListReady: icon = m_bmp_empty; msg = _L("No files [%d]"); break; case PrinterFileSystem::ListReady: icon = extra == 0 ? m_bmp_empty : m_bmp_failed; msg = extra == 0 ? _L("No files [%d]") : _L("Load failed [%d]"); break;
} }
if (fs->GetCount() == 0 && !msg.empty()) if (fs->GetCount() == 0 && !msg.empty())
m_image_grid->SetStatus(icon, msg); m_image_grid->SetStatus(icon, msg);
@ -449,15 +450,15 @@ void Slic3r::GUI::MediaFilePanel::doAction(size_t index, int action)
{ {
auto fs = m_image_grid->GetFileSystem(); auto fs = m_image_grid->GetFileSystem();
if (action == 0) { if (action == 0) {
if (fs->GetSelectCount() > 1) { if (index == -1) {
MessageDialog dlg(this, MessageDialog dlg(this,
wxString::Format(_L("You are going to delete %u files from printer. Are you sure to continue?"), fs->GetSelectCount()), wxString::Format(_L("You are going to delete %u files from printer. Are you sure to continue?"), fs->GetSelectCount()),
_L("Delete files"), wxYES_NO | wxICON_WARNING); _L("Delete files"), wxYES_NO | wxICON_WARNING);
if (dlg.ShowModal() != wxID_YES) if (dlg.ShowModal() != wxID_YES)
return; return;
} else if (index >= 0) { } else {
MessageDialog dlg(this, MessageDialog dlg(this,
wxString::Format(_L("Do you want to delete the file '%s' from printer?"), fs->GetSelectCount()), wxString::Format(_L("Do you want to delete the file '%s' from printer?"), from_u8(fs->GetFile(index).name)),
_L("Delete file"), wxYES_NO | wxICON_WARNING); _L("Delete file"), wxYES_NO | wxICON_WARNING);
if (dlg.ShowModal() != wxID_YES) if (dlg.ShowModal() != wxID_YES)
return; return;

View file

@ -608,7 +608,7 @@ void PrinterFileSystem::DownloadNextFile()
download->ofs.write((char const *) data, size); download->ofs.write((char const *) data, size);
download->boost_md5.process_bytes(data, size); download->boost_md5.process_bytes(data, size);
prog.size += size; prog.size += size;
if (prog.size < prog.total) { return CONTINUE; } if (prog.size < prog.total) { return 0; }
download->ofs.close(); download->ofs.close();
int result = 0; int result = 0;
std::string md5 = resp["file_md5"]; std::string md5 = resp["file_md5"];
@ -620,7 +620,12 @@ void PrinterFileSystem::DownloadNextFile()
std::string str_md5; std::string str_md5;
const auto char_digest = reinterpret_cast<const char *>(&digest[0]); const auto char_digest = reinterpret_cast<const char *>(&digest[0]);
boost::algorithm::hex(char_digest, char_digest + sizeof(digest), std::back_inserter(str_md5)); boost::algorithm::hex(char_digest, char_digest + sizeof(digest), std::back_inserter(str_md5));
if (!boost::iequals(str_md5, md5)) result = FILE_CHECK_ERR; if (!boost::iequals(str_md5, md5)) {
wxLogWarning("PrinterFileSystem::DownloadNextFile checksum error: %s != %s\n", str_md5, md5);
boost::system::error_code ec;
boost::filesystem::rename(download->local_path, download->local_path + ".tmp", ec);
result = FILE_CHECK_ERR;
}
} else { } else {
result = FILE_SIZE_ERR; result = FILE_SIZE_ERR;
} }
@ -637,8 +642,10 @@ void PrinterFileSystem::DownloadNextFile()
int progress = data.size * 100 / data.total; int progress = data.size * 100 / data.total;
auto & file = m_file_list[download->index]; auto & file = m_file_list[download->index];
if (result == ERROR_CANCEL) if (result == ERROR_CANCEL)
file.flags &= ~FF_DOWNLOAD; progress = -1, file.flags &= ~FF_DOWNLOAD;
else if (file.progress != progress) { else if (result != CONTINUE && result != SUCCESS)
progress == -2;
if (file.progress != progress) {
file.progress = progress; file.progress = progress;
SendChangedEvent(EVT_DOWNLOAD, download->index, file.local_path, result); SendChangedEvent(EVT_DOWNLOAD, download->index, file.local_path, result);
} }
@ -713,7 +720,7 @@ bool PrinterFileSystem::ParseThumbnail(File &file, std::istream &is)
} }
file.metadata.emplace("Title", model.model_info->model_name); file.metadata.emplace("Title", model.model_info->model_name);
file.metadata.emplace("Time", durationString(round(time))); file.metadata.emplace("Time", durationString(round(time)));
file.metadata.emplace("Weight", std::to_string(int(round(weight)))); file.metadata.emplace("Weight", std::to_string(int(round(weight))) + 'g');
auto thumbnail = model.model_info->metadata_items["Thumbnail"]; auto thumbnail = model.model_info->metadata_items["Thumbnail"];
if (thumbnail.empty() && !plate_data_list.empty()) { if (thumbnail.empty() && !plate_data_list.empty()) {
thumbnail = plate_data_list.front()->thumbnail_file; thumbnail = plate_data_list.front()->thumbnail_file;
@ -915,7 +922,7 @@ boost::uint32_t PrinterFileSystem::SendRequest(int type, json const &req, callba
auto msg = oss.str(); auto msg = oss.str();
//OutputDebugStringA(msg.c_str()); //OutputDebugStringA(msg.c_str());
//OutputDebugStringA("\n"); //OutputDebugStringA("\n");
wxLogMessage("PrinterFileSystem::SendRequest: \n%s\n", msg); wxLogInfo("PrinterFileSystem::SendRequest >>>: \n%s\n", wxString::FromUTF8(msg));
boost::unique_lock l(m_mutex); boost::unique_lock l(m_mutex);
m_messages.push_back(msg); m_messages.push_back(msg);
m_callbacks.push_back(callback); m_callbacks.push_back(callback);
@ -1013,7 +1020,7 @@ void PrinterFileSystem::HandleResponse(boost::unique_lock<boost::mutex> &l, Bamb
json root; json root;
//OutputDebugStringA(msg.c_str()); //OutputDebugStringA(msg.c_str());
//OutputDebugStringA("\n"); //OutputDebugStringA("\n");
wxLogMessage("PrinterFileSystem::HandleResponse: \n%s\n", msg); wxLogInfo("PrinterFileSystem::HandleResponse <<<: \n%s\n", wxString::FromUTF8(msg));
std::istringstream iss(msg); std::istringstream iss(msg);
int cmd = 0; int cmd = 0;
int seq = -1; int seq = -1;
@ -1068,6 +1075,7 @@ void PrinterFileSystem::Reconnect(boost::unique_lock<boost::mutex> &l, int resul
if (m_session.tunnel) { if (m_session.tunnel) {
auto tunnel = m_session.tunnel; auto tunnel = m_session.tunnel;
m_session.tunnel = nullptr; m_session.tunnel = nullptr;
wxLogMessage("PrinterFileSystem::Reconnect close");
l.unlock(); l.unlock();
Bambu_Close(tunnel); Bambu_Close(tunnel);
Bambu_Destroy(tunnel); Bambu_Destroy(tunnel);
@ -1089,6 +1097,7 @@ void PrinterFileSystem::Reconnect(boost::unique_lock<boost::mutex> &l, int resul
return; return;
m_cond.wait(l); m_cond.wait(l);
} }
wxLogMessage("PrinterFileSystem::Reconnect Initializing");
m_status = Status::Initializing; m_status = Status::Initializing;
SendChangedEvent(EVT_STATUS_CHANGED, m_status); SendChangedEvent(EVT_STATUS_CHANGED, m_status);
// wait for url // wait for url
@ -1098,10 +1107,13 @@ void PrinterFileSystem::Reconnect(boost::unique_lock<boost::mutex> &l, int resul
std::string url = m_messages.front(); std::string url = m_messages.front();
m_messages.clear(); m_messages.clear();
if (url.size() < 2) { if (url.size() < 2) {
wxLogMessage("PrinterFileSystem::Reconnect Initialize failed: %s", wxString::FromUTF8(url));
m_last_error = atoi(url.c_str()); m_last_error = atoi(url.c_str());
} else { } else {
wxLogMessage("PrinterFileSystem::Reconnect Initialized: %s", wxString::FromUTF8(url));
l.unlock(); l.unlock();
m_status = Status::Connecting; m_status = Status::Connecting;
wxLogMessage("PrinterFileSystem::Reconnect Connecting");
SendChangedEvent(EVT_STATUS_CHANGED, m_status); SendChangedEvent(EVT_STATUS_CHANGED, m_status);
Bambu_Tunnel tunnel = nullptr; Bambu_Tunnel tunnel = nullptr;
int ret = Bambu_Create(&tunnel, url.c_str()); int ret = Bambu_Create(&tunnel, url.c_str());
@ -1114,6 +1126,7 @@ void PrinterFileSystem::Reconnect(boost::unique_lock<boost::mutex> &l, int resul
l.lock(); l.lock();
if (ret == 0) { if (ret == 0) {
m_session.tunnel = tunnel; m_session.tunnel = tunnel;
wxLogMessage("PrinterFileSystem::Reconnect Connected");
break; break;
} }
if (tunnel) { if (tunnel) {
@ -1122,7 +1135,8 @@ void PrinterFileSystem::Reconnect(boost::unique_lock<boost::mutex> &l, int resul
} }
m_last_error = ret; m_last_error = ret;
} }
m_status = Status::Failed; wxLogMessage("PrinterFileSystem::Reconnect Failed");
m_status = Status::Failed;
SendChangedEvent(EVT_STATUS_CHANGED, m_status, "", url.size() < 2 ? 1 : 0); SendChangedEvent(EVT_STATUS_CHANGED, m_status, "", url.size() < 2 ? 1 : 0);
m_cond.timed_wait(l, boost::posix_time::seconds(10)); m_cond.timed_wait(l, boost::posix_time::seconds(10));
} }