Minor fixes downloading preset repo assets

Author: barzto@gmail.com
This commit is contained in:
David Kocik 2024-04-11 16:23:24 +02:00
parent ece5207783
commit 3e9c9d9558
7 changed files with 59 additions and 7 deletions

View File

@ -42,6 +42,8 @@ option(SLIC3R_MSVC_PDB "Generate PDB files on MSVC in Release mode" 1)
option(SLIC3R_ASAN "Enable ASan on Clang and GCC" 0)
option(SLIC3R_UBSAN "Enable UBSan on Clang and GCC" 0)
option(SLIC3R_ENABLE_FORMAT_STEP "Enable compilation of STEP file support" ON)
option(SLIC3R_LOG_TO_FILE "Enable logging into file")
option(SLIC3R_REPO_URL "Preset repo URL")
# SLIC3R_OPENGL_ES can be enabled only if SLIC3R_GUI is enabled.
CMAKE_DEPENDENT_OPTION(SLIC3R_OPENGL_ES "Compile PrusaSlicer targeting OpenGL ES" OFF "SLIC3R_GUI" OFF)
@ -98,6 +100,12 @@ foreach (_cache_var ${_cache_vars})
endif ()
endforeach()
if (SLIC3R_LOG_TO_FILE)
add_definitions(-DSLIC3R_LOG_TO_FILE)
endif ()
if (SLIC3R_REPO_URL)
add_definitions(-DSLIC3R_REPO_URL="${SLIC3R_REPO_URL}")
endif()
if (SLIC3R_GUI)
add_definitions(-DSLIC3R_GUI)
endif ()

View File

@ -342,7 +342,7 @@ template<class T>
struct NilValueTempl<T, std::enable_if_t<std::is_enum_v<T>, void>>
{
using NilType = T;
static constexpr auto value = static_cast<T>(std::numeric_limits<std::underlying_type_t<T>>::max());
static constexpr auto value = static_cast<std::underlying_type_t<T>>(std::numeric_limits<std::underlying_type_t<T>>::max());
};
template<class T> struct NilValueTempl<T, std::enable_if_t<std::is_floating_point_v<T>, void>> {

View File

@ -159,6 +159,9 @@ VendorProfile VendorProfile::from_ini(const ptree &tree, const boost::filesystem
const auto repo_id = vendor_section.find("repo_id");
if (repo_id != vendor_section.not_found()) {
res.repo_id = repo_id->second.data();
} else {
// For backward compatibility assume all profiles without repo_id are from "prod" repo
res.repo_id = "prod";
}
if (! load_all) {

View File

@ -2993,6 +2993,15 @@ void GUI_App::MacOpenURL(const wxString& url)
{
std::string narrow_url = into_u8(url);
if (boost::starts_with(narrow_url, "prusaslicer://open?file=")) {
// This app config field applies only to downloading file
// (we need to handle login URL even if this flag is set off)
if (app_config && !app_config->get_bool("downloader_url_registered"))
{
notification_manager()->push_notification(NotificationType::URLNotRegistered);
BOOST_LOG_TRIVIAL(error) << "Recieved command to open URL, but it is not allowed in app configuration. URL: " << url;
return;
}
start_download(std::move(narrow_url));
} else if (boost::starts_with(narrow_url, "prusaslicer://login")) {
plater()->get_user_account()->on_login_code_recieved(std::move(narrow_url));

View File

@ -5,7 +5,8 @@
#include "libslic3r/Technologies.hpp"
#include "GUI_Init.hpp"
#include "libslic3r/AppConfig.hpp"
#include "libslic3r/AppConfig.hpp"
#include "libslic3r/Utils/DirectoriesUtils.hpp"
#include "slic3r/GUI/GUI.hpp"
#include "slic3r/GUI/GUI_App.hpp"
@ -22,6 +23,9 @@
#include <boost/nowide/iostream.hpp>
#include <boost/nowide/convert.hpp>
#include <boost/log/trivial.hpp>
#include <boost/log/expressions.hpp>
#include <boost/log/utility/setup/file.hpp>
#if __APPLE__
#include <signal.h>
@ -45,6 +49,11 @@ int GUI_Run(GUI_InitParams &params)
signal(SIGCHLD, SIG_DFL);
#endif // __APPLE__
#ifdef SLIC3R_LOG_TO_FILE
auto sink = boost::log::add_file_log(get_default_datadir() + "/slicer.log");
sink->locked_backend()->auto_flush();
boost::log::core::get()->set_filter(boost::log::trivial::severity >= boost::log::trivial::info);
#endif // SLIC3R_LOG_TO_FILE
try {
GUI::GUI_App* gui = new GUI::GUI_App(params.start_as_gcodeviewer ? GUI::GUI_App::EAppMode::GCodeViewer : GUI::GUI_App::EAppMode::Editor);
if (gui->get_app_mode() != GUI::GUI_App::EAppMode::GCodeViewer) {

View File

@ -2,6 +2,9 @@
#include "slic3r/Utils/Http.hpp"
#include "slic3r/GUI/format.hpp"
#include "slic3r/GUI/GUI_App.hpp"
#include "slic3r/GUI/Plater.hpp"
#include "slic3r/GUI/UserAccount.hpp"
#include "libslic3r/Utils.hpp"
#include "libslic3r/AppConfig.hpp"
#include "libslic3r/miniz_extension.hpp"
@ -193,6 +196,15 @@ std::string escape_path_by_element(const std::string& path_string)
}
return ret_val;
}
void add_authorization_header(Http& http)
{
const std::string access_token = GUI::wxGetApp().plater()->get_user_account()->get_access_token();
if (!access_token.empty()) {
http.header("Authorization", "Bearer " + access_token);
}
}
}
bool OnlineArchiveRepository::get_file_inner(const std::string& url, const fs::path& target_path) const
@ -206,7 +218,9 @@ bool OnlineArchiveRepository::get_file_inner(const std::string& url, const fs::p
target_path.string(),
tmp_path.string());
Http::get(url)
auto http = Http::get(url);
add_authorization_header(http);
http
.on_progress([](Http::Progress, bool& cancel) {
//if (cancel) { cancel = true; }
})
@ -363,8 +377,14 @@ std::string test_json(bool secret)
bool sync_inner(std::string& manifest)
{
bool ret = false;
std::string url = "http://10.24.3.3:8001/v1/repos";
Http::get(std::move(url))
#ifdef SLIC3R_REPO_URL
std::string url = SLIC3R_REPO_URL;
#else
std::string url = "http://10.24.3.3:8001/v1/repos";
#endif
auto http = Http::get(std::move(url));
add_authorization_header(http);
http
.on_error([&](std::string body, std::string error, unsigned http_status) {
BOOST_LOG_TRIVIAL(error) << "Failed to get online archive repository manifests: "<< body << " ; " << error << " ; " << http_status;
ret = false;

View File

@ -7,7 +7,9 @@
#include <vector>
#include <memory>
class boost::filesystem::path;
namespace boost::filesystem {
class path;
}
namespace Slic3r {
class AppConfig;
@ -46,7 +48,7 @@ public:
};
// Use std::move when calling constructor.
ArchiveRepository(RepositoryManifest&& data) : m_data(std::move(data)) {}
~ArchiveRepository() {}
virtual ~ArchiveRepository() {}
// Gets vendor_indices.zip to target_path
virtual bool get_archive(const boost::filesystem::path& target_path) const = 0;
// Gets file if repository_id arg matches m_id.
@ -80,6 +82,7 @@ public:
private:
bool get_file_inner(const std::string& url, const boost::filesystem::path& target_path) const;
};
class LocalArchiveRepository : public ArchiveRepository
{
public: