diff --git a/CMakeLists.txt b/CMakeLists.txt index 5445eb99b1..919df51a01 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 () diff --git a/src/libslic3r/Config.hpp b/src/libslic3r/Config.hpp index 7f922481e2..0b743ac22d 100644 --- a/src/libslic3r/Config.hpp +++ b/src/libslic3r/Config.hpp @@ -342,7 +342,7 @@ template struct NilValueTempl, void>> { using NilType = T; - static constexpr auto value = static_cast(std::numeric_limits>::max()); + static constexpr auto value = static_cast>(std::numeric_limits>::max()); }; template struct NilValueTempl, void>> { diff --git a/src/libslic3r/Preset.cpp b/src/libslic3r/Preset.cpp index ad7b3cb9ee..3159aacaad 100644 --- a/src/libslic3r/Preset.cpp +++ b/src/libslic3r/Preset.cpp @@ -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) { diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index caccd2a711..6074a2765b 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -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)); diff --git a/src/slic3r/GUI/GUI_Init.cpp b/src/slic3r/GUI/GUI_Init.cpp index 504a42a932..2c74971ce2 100644 --- a/src/slic3r/GUI/GUI_Init.cpp +++ b/src/slic3r/GUI/GUI_Init.cpp @@ -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 #include +#include +#include +#include #if __APPLE__ #include @@ -45,6 +49,11 @@ int GUI_Run(GUI_InitParams ¶ms) 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) { diff --git a/src/slic3r/GUI/PresetArchiveDatabase.cpp b/src/slic3r/GUI/PresetArchiveDatabase.cpp index b8ea8c7ab2..632c8991af 100644 --- a/src/slic3r/GUI/PresetArchiveDatabase.cpp +++ b/src/slic3r/GUI/PresetArchiveDatabase.cpp @@ -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; diff --git a/src/slic3r/GUI/PresetArchiveDatabase.hpp b/src/slic3r/GUI/PresetArchiveDatabase.hpp index 5b52c0e897..6f19cd70e7 100644 --- a/src/slic3r/GUI/PresetArchiveDatabase.hpp +++ b/src/slic3r/GUI/PresetArchiveDatabase.hpp @@ -7,7 +7,9 @@ #include #include -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: