mirror of
				https://github.com/SoftFever/OrcaSlicer.git
				synced 2025-10-31 04:31:15 -06:00 
			
		
		
		
	FIX: [STUDIO-2964] something with fix printer file management
Change-Id: Id8c2349766c8ca3f90a0985873726a72f760da50
This commit is contained in:
		
							parent
							
								
									f5960411a3
								
							
						
					
					
						commit
						e48170e7fe
					
				
					 3 changed files with 29 additions and 13 deletions
				
			
		|  | @ -638,6 +638,7 @@ void Slic3r::GUI::ImageGrid::renderContent2(wxDC &dc, wxPoint const &pt, int ind | |||
|     // Draw thumbnail & buttons
 | ||||
|     int h = m_content_rect.GetHeight() * 64 / 264; | ||||
|     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); | ||||
|     m_content_rect.SetHeight(m_content_rect.GetHeight() + h); | ||||
|     // Draw info bar
 | ||||
|  |  | |||
|  | @ -267,12 +267,13 @@ void MediaFilePanel::SetMachineObject(MachineObject* obj) | |||
|             ScalableBitmap icon; | ||||
|             wxString msg; | ||||
|             int status = e.GetInt(); | ||||
|             int extra = e.GetExtraLong(); | ||||
|             switch (status) { | ||||
|             case PrinterFileSystem::Initializing: icon = m_bmp_loading; msg = _L("Initializing..."); 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::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()) | ||||
|                 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(); | ||||
|     if (action == 0) { | ||||
|         if (fs->GetSelectCount() > 1) { | ||||
|         if (index == -1) { | ||||
|             MessageDialog dlg(this,  | ||||
|                 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); | ||||
|             if (dlg.ShowModal() != wxID_YES) | ||||
|                 return; | ||||
|         } else if (index >= 0) { | ||||
|         } else { | ||||
|             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); | ||||
|             if (dlg.ShowModal() != wxID_YES) | ||||
|                 return; | ||||
|  |  | |||
|  | @ -608,7 +608,7 @@ void PrinterFileSystem::DownloadNextFile() | |||
|             download->ofs.write((char const *) data, size); | ||||
|             download->boost_md5.process_bytes(data, size); | ||||
|             prog.size += size; | ||||
|             if (prog.size < prog.total) { return CONTINUE; } | ||||
|             if (prog.size < prog.total) { return 0; } | ||||
|             download->ofs.close(); | ||||
|             int         result = 0; | ||||
|             std::string md5    = resp["file_md5"]; | ||||
|  | @ -620,7 +620,12 @@ void PrinterFileSystem::DownloadNextFile() | |||
|                 std::string str_md5; | ||||
|                 const auto  char_digest = reinterpret_cast<const char *>(&digest[0]); | ||||
|                 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 { | ||||
|                 result = FILE_SIZE_ERR; | ||||
|             } | ||||
|  | @ -637,8 +642,10 @@ void PrinterFileSystem::DownloadNextFile() | |||
|                 int progress = data.size * 100 / data.total; | ||||
|                 auto & file = m_file_list[download->index]; | ||||
|                 if (result == ERROR_CANCEL) | ||||
|                     file.flags &= ~FF_DOWNLOAD; | ||||
|                 else if (file.progress != progress) { | ||||
|                     progress = -1, file.flags &= ~FF_DOWNLOAD; | ||||
|                 else if (result != CONTINUE && result != SUCCESS) | ||||
|                     progress == -2; | ||||
|                 if (file.progress != progress) { | ||||
|                     file.progress = progress; | ||||
|                     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("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"]; | ||||
|     if (thumbnail.empty() && !plate_data_list.empty()) { | ||||
|         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(); | ||||
|     //OutputDebugStringA(msg.c_str());
 | ||||
|     //OutputDebugStringA("\n");
 | ||||
|     wxLogMessage("PrinterFileSystem::SendRequest: \n%s\n", msg); | ||||
|     wxLogInfo("PrinterFileSystem::SendRequest >>>: \n%s\n", wxString::FromUTF8(msg)); | ||||
|     boost::unique_lock l(m_mutex); | ||||
|     m_messages.push_back(msg); | ||||
|     m_callbacks.push_back(callback); | ||||
|  | @ -1013,7 +1020,7 @@ void PrinterFileSystem::HandleResponse(boost::unique_lock<boost::mutex> &l, Bamb | |||
|     json        root; | ||||
|     //OutputDebugStringA(msg.c_str());
 | ||||
|     //OutputDebugStringA("\n");
 | ||||
|     wxLogMessage("PrinterFileSystem::HandleResponse: \n%s\n", msg); | ||||
|     wxLogInfo("PrinterFileSystem::HandleResponse <<<: \n%s\n", wxString::FromUTF8(msg)); | ||||
|     std::istringstream iss(msg); | ||||
|     int                cmd    = 0; | ||||
|     int                seq    = -1; | ||||
|  | @ -1068,6 +1075,7 @@ void PrinterFileSystem::Reconnect(boost::unique_lock<boost::mutex> &l, int resul | |||
|     if (m_session.tunnel) { | ||||
|         auto tunnel = m_session.tunnel; | ||||
|         m_session.tunnel = nullptr; | ||||
|         wxLogMessage("PrinterFileSystem::Reconnect close"); | ||||
|         l.unlock(); | ||||
|         Bambu_Close(tunnel); | ||||
|         Bambu_Destroy(tunnel); | ||||
|  | @ -1089,6 +1097,7 @@ void PrinterFileSystem::Reconnect(boost::unique_lock<boost::mutex> &l, int resul | |||
|                 return; | ||||
|             m_cond.wait(l); | ||||
|         } | ||||
|         wxLogMessage("PrinterFileSystem::Reconnect Initializing"); | ||||
|         m_status = Status::Initializing; | ||||
|         SendChangedEvent(EVT_STATUS_CHANGED, m_status); | ||||
|         // wait for url
 | ||||
|  | @ -1098,10 +1107,13 @@ void PrinterFileSystem::Reconnect(boost::unique_lock<boost::mutex> &l, int resul | |||
|         std::string url = m_messages.front(); | ||||
|         m_messages.clear(); | ||||
|         if (url.size() < 2) { | ||||
|             wxLogMessage("PrinterFileSystem::Reconnect Initialize failed: %s", wxString::FromUTF8(url)); | ||||
|             m_last_error = atoi(url.c_str()); | ||||
|         } else { | ||||
|             wxLogMessage("PrinterFileSystem::Reconnect Initialized: %s", wxString::FromUTF8(url)); | ||||
|             l.unlock(); | ||||
|             m_status = Status::Connecting; | ||||
|             wxLogMessage("PrinterFileSystem::Reconnect Connecting"); | ||||
|             SendChangedEvent(EVT_STATUS_CHANGED, m_status); | ||||
|             Bambu_Tunnel tunnel = nullptr; | ||||
|             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(); | ||||
|             if (ret == 0) { | ||||
|                 m_session.tunnel = tunnel; | ||||
|                 wxLogMessage("PrinterFileSystem::Reconnect Connected"); | ||||
|                 break; | ||||
|             } | ||||
|             if (tunnel) { | ||||
|  | @ -1122,7 +1135,8 @@ void PrinterFileSystem::Reconnect(boost::unique_lock<boost::mutex> &l, int resul | |||
|             } | ||||
|             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); | ||||
|         m_cond.timed_wait(l, boost::posix_time::seconds(10)); | ||||
|     } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 chunmao.guo
						chunmao.guo