Run downloader from url fix

This commit is contained in:
David Kocik 2022-06-03 16:04:00 +02:00
parent 28d4d53516
commit 212d741d30
7 changed files with 127 additions and 21 deletions

View File

@ -205,13 +205,12 @@ DownloadFrame::DownloadFrame(const wxString& title, const wxPoint& pos, const wx
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
if (url.starts_with("open?file=")) {
if (url.starts_with("prusaslicer://open/?file=")) {
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);
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));
//
wxVector<wxVariant> fields;
fields.push_back(wxVariant(std::to_wstring(id)));

View File

@ -77,7 +77,6 @@ void FileGet::priv::get_perform()
{
assert(m_evt_handler);
assert(!m_url.empty());
assert(!m_url.empty());
assert(!m_filename.empty());
assert(boost::filesystem::is_directory(m_dest_folder));

View File

@ -213,6 +213,8 @@ set(SLIC3R_GUI_SOURCES
GUI/DesktopIntegrationDialog.hpp
GUI/HintNotification.cpp
GUI/HintNotification.hpp
GUI/FileArchiveDialog.cpp
GUI/FileArchiveDialog.hpp
Utils/AppUpdater.cpp
Utils/AppUpdater.hpp
Utils/Http.cpp

View File

@ -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."));
auto* box_registry = new wxCheckBox(this, wxID_ANY, _L("Regitry for URL download"));
box_registry->SetValue(false);
/* auto* box_registry = new wxCheckBox(this, wxID_ANY, _L("Regitry for URL download"));
box_registry->SetValue(false);*/
auto* box_registry = new wxButton(this, wxID_ANY, _L("Registry for URL download"));
append(box_registry);
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_registry->Bind(wxEVT_CHECKBOX, [this](wxCommandEvent& event) {
if(!event.IsChecked())
return;
box_registry->Bind(wxEVT_BUTTON, [this](wxCommandEvent& event) {
//if(!event.IsChecked())
// return;
// 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_full(wxRegKey::HKCU, "Software\\Classes\\prusaslicer\\shell\\open\\command");
if (!key_first.Exists()) {
@ -1260,7 +1270,8 @@ PageUpdate::PageUpdate(ConfigWizard *parent)
if (!key_full.Exists()) {
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;
});
}

View 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

View 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_

View File

@ -95,6 +95,7 @@
#include "MsgDialog.hpp"
#include "ProjectDirtyStateManager.hpp"
#include "Gizmos/GLGizmoSimplify.hpp" // create suggestion notification
#include "FileArchiveDialog.hpp"
#ifdef __APPLE__
#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);
}
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_zero_struct(&archive);
if (!open_zip_reader(&archive, input_file.string()))
if (!open_zip_reader(&archive, archive_path.string()))
return ;
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;
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) {
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::replace(name.begin(), name.end(), '\\', '/');
files.push_back(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);