mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-09-14 12:37:46 +00:00
feature add download file for wcp logic.
This commit is contained in:
@@ -134,7 +134,6 @@ size_t DownloadManager::start_internal_download(const std::string& file_url,
|
|||||||
|
|
||||||
boost::filesystem::path dest_path_obj(dest_path);
|
boost::filesystem::path dest_path_obj(dest_path);
|
||||||
|
|
||||||
// Check if dest_path is a directory or a complete file path
|
|
||||||
boost::filesystem::path dest_file_path;
|
boost::filesystem::path dest_file_path;
|
||||||
if (boost::filesystem::is_directory(dest_path_obj) || dest_path_obj.filename().empty()) {
|
if (boost::filesystem::is_directory(dest_path_obj) || dest_path_obj.filename().empty()) {
|
||||||
// dest_path is a directory, need to append file_name
|
// dest_path is a directory, need to append file_name
|
||||||
@@ -148,11 +147,8 @@ size_t DownloadManager::start_internal_download(const std::string& file_url,
|
|||||||
dest_file_path = dest_path_obj;
|
dest_file_path = dest_path_obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create parent directory if it doesn't exist
|
|
||||||
boost::filesystem::create_directories(dest_file_path.parent_path());
|
boost::filesystem::create_directories(dest_file_path.parent_path());
|
||||||
|
|
||||||
// Generate unique file path if file already exists
|
|
||||||
// dest_file_path should now be the complete absolute path: directory + filename
|
|
||||||
std::string unique_dest_path = get_unique_file_path(dest_file_path);
|
std::string unique_dest_path = get_unique_file_path(dest_file_path);
|
||||||
|
|
||||||
auto task = std::make_shared<DownloadTask>(task_id,
|
auto task = std::make_shared<DownloadTask>(task_id,
|
||||||
|
|||||||
@@ -383,8 +383,9 @@ void GenericDownloadDialog::show_progress_page()
|
|||||||
|
|
||||||
void GenericDownloadDialog::show_complete_page()
|
void GenericDownloadDialog::show_complete_page()
|
||||||
{
|
{
|
||||||
m_simplebook_status->SetSelection(1);
|
//m_simplebook_status->SetSelection(1);
|
||||||
m_status_bar->hide_cancel_button();
|
//m_status_bar->hide_cancel_button();
|
||||||
|
EndModal(wxID_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GenericDownloadDialog::show_error_page(const std::string& error_msg)
|
void GenericDownloadDialog::show_error_page(const std::string& error_msg)
|
||||||
|
|||||||
@@ -2252,14 +2252,6 @@ static wxMenu* generate_help_menu()
|
|||||||
append_menu_item(
|
append_menu_item(
|
||||||
helpMenu, wxID_ANY, _L("Check for Update"), _L("Check for Update"),
|
helpMenu, wxID_ANY, _L("Check for Update"), _L("Check for Update"),
|
||||||
[](wxCommandEvent&) {
|
[](wxCommandEvent&) {
|
||||||
std::string fileUrl = "https://public.resource.snapmaker.com/model/public/3mf/test_for_download.3mf";
|
|
||||||
//std::string fileUrl = "https://github.com/Snapmaker/OrcaSlicer/releases/download/v2.2.1/Snapmaker_Orca_Windows_Installer_V2.2.1.exe";
|
|
||||||
std::string filename = "test_for_download.3mf";
|
|
||||||
std::string downloadPath = "C:/tmp";
|
|
||||||
|
|
||||||
GenericDownloadDialog dlg(_L("importing the model"), fileUrl, filename, downloadPath);
|
|
||||||
dlg.ShowModal();
|
|
||||||
return;
|
|
||||||
wxGetApp().check_new_version_sf(true, UPDATE_BUSER);
|
wxGetApp().check_new_version_sf(true, UPDATE_BUSER);
|
||||||
}, "", nullptr, []() {
|
}, "", nullptr, []() {
|
||||||
return true;
|
return true;
|
||||||
@@ -4015,6 +4007,38 @@ void MainFrame::RunScript(wxString js)
|
|||||||
m_webview->RunScript(js);
|
m_webview->RunScript(js);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainFrame::downloadOpenProject(const std::string& fileUrl, const std::string& fileName, std::string completeFilePath)
|
||||||
|
{
|
||||||
|
// std::string fileUrl = "https://public.resource.snapmaker.com/model/public/3mf/test_for_download.3mf";
|
||||||
|
// std::string filename = "test_for_download.3mf";
|
||||||
|
|
||||||
|
GenericDownloadDialog dlg(_L("downloading the model"), fileUrl, fileName, completeFilePath);
|
||||||
|
dlg.ShowModal();
|
||||||
|
|
||||||
|
if (completeFilePath.empty()) {
|
||||||
|
auto downloadPath = wxGetApp().app_config->get("download_path");
|
||||||
|
completeFilePath = downloadPath + "/" + fileName;
|
||||||
|
}
|
||||||
|
if (!boost::filesystem::exists(completeFilePath))
|
||||||
|
{
|
||||||
|
BOOST_LOG_TRIVIAL(warning) << boost::format("the file '%1%' not exists") % completeFilePath;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Auto-open project if it's a .3mf file
|
||||||
|
boost::filesystem::path path(completeFilePath);
|
||||||
|
std::string extension = boost::algorithm::to_lower_copy(path.extension().string());
|
||||||
|
if (extension == ".3mf") {
|
||||||
|
BOOST_LOG_TRIVIAL(info) << boost::format("GenericDownloadDialog: Auto-opening project file '%1%'") % completeFilePath;
|
||||||
|
wxString wx_file_path = wxString::FromUTF8(completeFilePath.c_str());
|
||||||
|
if (wxGetApp().can_load_project() && wxGetApp().mainframe && wxGetApp().mainframe->plater()) {
|
||||||
|
wxGetApp().mainframe->plater()->load_project(wx_file_path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void MainFrame::technology_changed()
|
void MainFrame::technology_changed()
|
||||||
{
|
{
|
||||||
// update menu titles
|
// update menu titles
|
||||||
|
|||||||
@@ -348,7 +348,11 @@ public:
|
|||||||
void load_printer_url();
|
void load_printer_url();
|
||||||
bool is_printer_view() const;
|
bool is_printer_view() const;
|
||||||
void refresh_plugin_tips();
|
void refresh_plugin_tips();
|
||||||
void RunScript(wxString js);
|
void RunScript(wxString js);
|
||||||
|
|
||||||
|
void downloadOpenProject(const std::string& fileUrl,
|
||||||
|
const std::string& fileName,
|
||||||
|
std::string completeFilePath = "");
|
||||||
|
|
||||||
//SoftFever
|
//SoftFever
|
||||||
void show_device(bool bBBLPrinter);
|
void show_device(bool bBBLPrinter);
|
||||||
|
|||||||
@@ -3187,14 +3187,10 @@ void SSWCP_MachineOption_Instance::sw_GetFileFilamentMapping()
|
|||||||
|
|
||||||
response["thumbnails"] = thumbnails;
|
response["thumbnails"] = thumbnails;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// file name
|
// file name
|
||||||
response["filename"] = SSWCP::get_display_filename();
|
response["filename"] = SSWCP::get_display_filename();
|
||||||
response["filepath"] = SSWCP::get_active_filename();
|
response["filepath"] = SSWCP::get_active_filename();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
m_res_data = response;
|
m_res_data = response;
|
||||||
send_to_js();
|
send_to_js();
|
||||||
finish_job();
|
finish_job();
|
||||||
@@ -4404,18 +4400,9 @@ void SSWCP_UserLogin_Instance::sw_DownloadFile()
|
|||||||
handle_general_fail(-1, "Download Manager not available");
|
handle_general_fail(-1, "Download Manager not available");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wxGetApp().mainframe->downloadOpenProject(fileUrl, fileName, "");
|
||||||
|
|
||||||
size_t task_id = download_mgr->start_wcp_download(fileUrl,
|
|
||||||
fileName,
|
|
||||||
shared_from_this(),
|
|
||||||
false); // use_original_event_id = false (sw_DownloadFile: finish immediately)
|
|
||||||
|
|
||||||
// Return task ID to Flutter
|
|
||||||
json response;
|
|
||||||
response["task_id"] = task_id;
|
|
||||||
response["file_name"] = fileName;
|
|
||||||
response["file_url"] = fileUrl;
|
|
||||||
m_res_data = response;
|
|
||||||
m_status = 0;
|
m_status = 0;
|
||||||
m_msg = "Download started";
|
m_msg = "Download started";
|
||||||
send_to_js();
|
send_to_js();
|
||||||
|
|||||||
Reference in New Issue
Block a user