mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-09-26 07:13:15 +08:00
Run downloader from url fix
This commit is contained in:
parent
28d4d53516
commit
212d741d30
@ -205,13 +205,12 @@ DownloadFrame::DownloadFrame(const wxString& title, const wxPoint& pos, const wx
|
|||||||
void DownloadFrame::start_download(wxString url)
|
void DownloadFrame::start_download(wxString url)
|
||||||
{
|
{
|
||||||
// prusaslicer://open?file=https%3A%2F%2Fmedia.printables.com%2Fmedia%2Fprints%2F152208%2Fstls%2F1431590_8b8287b3-03b1-4cbe-82d0-268a0affa171%2Ff1_logo.stl
|
// prusaslicer://open?file=https%3A%2F%2Fmedia.printables.com%2Fmedia%2Fprints%2F152208%2Fstls%2F1431590_8b8287b3-03b1-4cbe-82d0-268a0affa171%2Ff1_logo.stl
|
||||||
if (url.starts_with("open?file=")) {
|
if (url.starts_with("prusaslicer://open/?file=")) {
|
||||||
int id = get_next_id();
|
int id = get_next_id();
|
||||||
std::string escaped_url = FileGet::escape_url(boost::nowide::narrow(url.substr(10)));
|
std::string escaped_url = FileGet::escape_url(boost::nowide::narrow(url.substr(25)));
|
||||||
//log(std::to_string(id) + ": start " + escaped_url);
|
//log(std::to_string(id) + ": start " + escaped_url);
|
||||||
escaped_url = "https://media.printables.com/media/prints/216267/gcodes/1974221_32d21613-b567-4328-8261-49b46d9dd249/01_big_trex_skull_with_threads_015mm_pla_mk3_2d.gcode";
|
//escaped_url = "https://media.printables.com/media/prints/216267/gcodes/1974221_32d21613-b567-4328-8261-49b46d9dd249/01_big_trex_skull_with_threads_015mm_pla_mk3_2d.gcode";
|
||||||
m_downloads.emplace_back(std::make_unique<Download>(id, std::move(escaped_url), this, m_dest_folder));
|
m_downloads.emplace_back(std::make_unique<Download>(id, std::move(escaped_url), this, m_dest_folder));
|
||||||
//
|
|
||||||
|
|
||||||
wxVector<wxVariant> fields;
|
wxVector<wxVariant> fields;
|
||||||
fields.push_back(wxVariant(std::to_wstring(id)));
|
fields.push_back(wxVariant(std::to_wstring(id)));
|
||||||
|
@ -77,7 +77,6 @@ void FileGet::priv::get_perform()
|
|||||||
{
|
{
|
||||||
assert(m_evt_handler);
|
assert(m_evt_handler);
|
||||||
assert(!m_url.empty());
|
assert(!m_url.empty());
|
||||||
assert(!m_url.empty());
|
|
||||||
assert(!m_filename.empty());
|
assert(!m_filename.empty());
|
||||||
assert(boost::filesystem::is_directory(m_dest_folder));
|
assert(boost::filesystem::is_directory(m_dest_folder));
|
||||||
|
|
||||||
|
@ -213,6 +213,8 @@ set(SLIC3R_GUI_SOURCES
|
|||||||
GUI/DesktopIntegrationDialog.hpp
|
GUI/DesktopIntegrationDialog.hpp
|
||||||
GUI/HintNotification.cpp
|
GUI/HintNotification.cpp
|
||||||
GUI/HintNotification.hpp
|
GUI/HintNotification.hpp
|
||||||
|
GUI/FileArchiveDialog.cpp
|
||||||
|
GUI/FileArchiveDialog.hpp
|
||||||
Utils/AppUpdater.cpp
|
Utils/AppUpdater.cpp
|
||||||
Utils/AppUpdater.hpp
|
Utils/AppUpdater.hpp
|
||||||
Utils/Http.cpp
|
Utils/Http.cpp
|
||||||
|
@ -1239,17 +1239,27 @@ PageUpdate::PageUpdate(ConfigWizard *parent)
|
|||||||
append_text(_L("Additionally a backup snapshot of the whole configuration is created before an update is applied."));
|
append_text(_L("Additionally a backup snapshot of the whole configuration is created before an update is applied."));
|
||||||
|
|
||||||
|
|
||||||
auto* box_registry = new wxCheckBox(this, wxID_ANY, _L("Regitry for URL download"));
|
/* auto* box_registry = new wxCheckBox(this, wxID_ANY, _L("Regitry for URL download"));
|
||||||
box_registry->SetValue(false);
|
box_registry->SetValue(false);*/
|
||||||
|
auto* box_registry = new wxButton(this, wxID_ANY, _L("Registry for URL download"));
|
||||||
append(box_registry);
|
append(box_registry);
|
||||||
|
|
||||||
box_slic3r->Bind(wxEVT_CHECKBOX, [this](wxCommandEvent &event) { this->version_check = event.IsChecked(); });
|
box_slic3r->Bind(wxEVT_CHECKBOX, [this](wxCommandEvent &event) { this->version_check = event.IsChecked(); });
|
||||||
box_presets->Bind(wxEVT_CHECKBOX, [this](wxCommandEvent &event) { this->preset_update = event.IsChecked(); });
|
box_presets->Bind(wxEVT_CHECKBOX, [this](wxCommandEvent &event) { this->preset_update = event.IsChecked(); });
|
||||||
|
|
||||||
box_registry->Bind(wxEVT_CHECKBOX, [this](wxCommandEvent& event) {
|
box_registry->Bind(wxEVT_BUTTON, [this](wxCommandEvent& event) {
|
||||||
if(!event.IsChecked())
|
//if(!event.IsChecked())
|
||||||
return;
|
// return;
|
||||||
// Registry key creation for "prusaslicer://" URL
|
// Registry key creation for "prusaslicer://" URL
|
||||||
|
|
||||||
|
boost::filesystem::path binary_path(resources_dir());
|
||||||
|
|
||||||
|
binary_path = binary_path.parent_path() / "prusa-slicer-downloader.exe";
|
||||||
|
|
||||||
|
std::string binary_string = binary_path.string();
|
||||||
|
|
||||||
|
std::string key_string = "\"" + binary_string + "\" \"-u\" \"%1\"";
|
||||||
|
|
||||||
wxRegKey key_first(wxRegKey::HKCU, "Software\\Classes\\prusaslicer");
|
wxRegKey key_first(wxRegKey::HKCU, "Software\\Classes\\prusaslicer");
|
||||||
wxRegKey key_full(wxRegKey::HKCU, "Software\\Classes\\prusaslicer\\shell\\open\\command");
|
wxRegKey key_full(wxRegKey::HKCU, "Software\\Classes\\prusaslicer\\shell\\open\\command");
|
||||||
if (!key_first.Exists()) {
|
if (!key_first.Exists()) {
|
||||||
@ -1260,7 +1270,8 @@ PageUpdate::PageUpdate(ConfigWizard *parent)
|
|||||||
if (!key_full.Exists()) {
|
if (!key_full.Exists()) {
|
||||||
key_full.Create(false);
|
key_full.Create(false);
|
||||||
}
|
}
|
||||||
key_full = "\"C:\\Program Files\\Prusa3D\\PrusaSlicer\\prusa-slicer-console.exe\" \"%1\"";
|
//key_full = "\"C:\\Program Files\\Prusa3D\\PrusaSlicer\\prusa-slicer-console.exe\" \"%1\"";
|
||||||
|
key_full = key_string;
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
23
src/slic3r/GUI/FileArchiveDialog.cpp
Normal file
23
src/slic3r/GUI/FileArchiveDialog.cpp
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
#include "FileArchiveDialog.hpp"
|
||||||
|
|
||||||
|
#include "I18N.hpp"
|
||||||
|
#include "GUI_App.hpp"
|
||||||
|
#include "GUI.hpp"
|
||||||
|
#include "MainFrame.hpp"
|
||||||
|
|
||||||
|
namespace Slic3r {
|
||||||
|
namespace GUI {
|
||||||
|
|
||||||
|
FileArchiveDialog::FileArchiveDialog(const std::vector<std::string>& files)
|
||||||
|
: DPIDialog(static_cast<wxWindow*>(wxGetApp().mainframe), wxID_ANY, _(L("Archive preview")), wxDefaultPosition,
|
||||||
|
wxSize(45 * wxGetApp().em_unit(), 40 * wxGetApp().em_unit()),
|
||||||
|
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxMAXIMIZE_BOX)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void FileArchiveDialog::on_dpi_changed(const wxRect& suggested_rect)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace GUI
|
||||||
|
} // namespace Slic3r
|
30
src/slic3r/GUI/FileArchiveDialog.hpp
Normal file
30
src/slic3r/GUI/FileArchiveDialog.hpp
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#ifndef slic3r_GUI_FileArchiveDialog_hpp_
|
||||||
|
#define slic3r_GUI_FileArchiveDialog_hpp_
|
||||||
|
|
||||||
|
#include "GUI_Utils.hpp"
|
||||||
|
#include <wx/wx.h>
|
||||||
|
|
||||||
|
|
||||||
|
namespace Slic3r {
|
||||||
|
namespace GUI {
|
||||||
|
|
||||||
|
class FileArchiveDialog : public DPIDialog
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
FileArchiveDialog(const std::vector<std::string>& files);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void on_dpi_changed(const wxRect& suggested_rect) override;
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace GU
|
||||||
|
} // namespace Slic3r
|
||||||
|
#endif // slic3r_GUI_FileArchiveDialog_hpp_
|
@ -95,6 +95,7 @@
|
|||||||
#include "MsgDialog.hpp"
|
#include "MsgDialog.hpp"
|
||||||
#include "ProjectDirtyStateManager.hpp"
|
#include "ProjectDirtyStateManager.hpp"
|
||||||
#include "Gizmos/GLGizmoSimplify.hpp" // create suggestion notification
|
#include "Gizmos/GLGizmoSimplify.hpp" // create suggestion notification
|
||||||
|
#include "FileArchiveDialog.hpp"
|
||||||
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
#include "Gizmos/GLGizmosManager.hpp"
|
#include "Gizmos/GLGizmosManager.hpp"
|
||||||
@ -5453,32 +5454,73 @@ std::vector<size_t> Plater::load_files(const std::vector<std::string>& input_fil
|
|||||||
return p->load_files(paths, load_model, load_config, imperial_units);
|
return p->load_files(paths, load_model, load_config, imperial_units);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Plater::preview_archive(const boost::filesystem::path& input_file)
|
void Plater::preview_archive(const boost::filesystem::path& archive_path)
|
||||||
{
|
{
|
||||||
BOOST_LOG_TRIVIAL(error) << "preview zip archive: " << input_file;
|
BOOST_LOG_TRIVIAL(error) << "preview zip archive: " << archive_path;
|
||||||
|
|
||||||
mz_zip_archive archive;
|
mz_zip_archive archive;
|
||||||
mz_zip_zero_struct(&archive);
|
mz_zip_zero_struct(&archive);
|
||||||
|
|
||||||
if (!open_zip_reader(&archive, input_file.string()))
|
if (!open_zip_reader(&archive, archive_path.string()))
|
||||||
return ;
|
return ;
|
||||||
|
|
||||||
mz_uint num_entries = mz_zip_reader_get_num_files(&archive);
|
mz_uint num_entries = mz_zip_reader_get_num_files(&archive);
|
||||||
|
|
||||||
BOOST_LOG_TRIVIAL(error) << "entries: " << num_entries;
|
//BOOST_LOG_TRIVIAL(error) << "entries: " << num_entries;
|
||||||
|
|
||||||
|
|
||||||
mz_zip_archive_file_stat stat;
|
mz_zip_archive_file_stat stat;
|
||||||
bool config_found = false;
|
|
||||||
|
//bool config_found = false;
|
||||||
|
//for (mz_uint i = 0; i < num_entries; ++i) {
|
||||||
|
// if (mz_zip_reader_file_stat(&archive, i, &stat)) {
|
||||||
|
// std::string name(stat.m_filename);
|
||||||
|
// //std::replace(name.begin(), name.end(), '\\', '/');
|
||||||
|
|
||||||
|
// BOOST_LOG_TRIVIAL(error) << name;
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
|
std::string archive_path_string = archive_path.string();
|
||||||
|
archive_path_string = archive_path_string.substr(0, archive_path_string.size() - 4);
|
||||||
|
boost::filesystem::path archive_dir(archive_path_string);
|
||||||
|
|
||||||
|
|
||||||
|
if (!boost::filesystem::is_directory(archive_dir) &&
|
||||||
|
!boost::filesystem::create_directory(archive_dir))
|
||||||
|
return;
|
||||||
|
|
||||||
|
std::replace(archive_path_string.begin(), archive_path_string.end(), '\\', '/');
|
||||||
|
|
||||||
|
std::vector<std::string> files;
|
||||||
|
|
||||||
|
// we first loop the entries to read from the archive the .model file only, in order to extract the version from it
|
||||||
for (mz_uint i = 0; i < num_entries; ++i) {
|
for (mz_uint i = 0; i < num_entries; ++i) {
|
||||||
if (mz_zip_reader_file_stat(&archive, i, &stat)) {
|
if (mz_zip_reader_file_stat(&archive, i, &stat)) {
|
||||||
std::string name(stat.m_filename);
|
std::string name(stat.m_filename);
|
||||||
//std::replace(name.begin(), name.end(), '\\', '/');
|
std::replace(name.begin(), name.end(), '\\', '/');
|
||||||
|
files.push_back(name);
|
||||||
BOOST_LOG_TRIVIAL(error) << name;
|
if (boost::algorithm::iends_with(name, ".stl")) {
|
||||||
|
try
|
||||||
|
{
|
||||||
|
std::string final_path = archive_path_string + "/" + name;
|
||||||
|
bool res = mz_zip_reader_extract_file_to_file(&archive, stat.m_filename, final_path.c_str(), 0);
|
||||||
|
//bool res = mz_zip_reader_extract_file_to_callback(&archive, stat.m_filename, [](void* pOpaque, mz_uint64 file_ofs, const void* pBuf, size_t n)->size_t {}, &data, 0);
|
||||||
|
}
|
||||||
|
catch (const std::exception& e)
|
||||||
|
{
|
||||||
|
// ensure the zip archive is closed and rethrow the exception
|
||||||
|
close_zip_reader(&archive);
|
||||||
|
throw Slic3r::FileIOError(e.what());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FileArchiveDialog dlg(files);
|
||||||
|
dlg.ShowModal();
|
||||||
|
|
||||||
close_zip_reader(&archive);
|
close_zip_reader(&archive);
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user