From 9f1d47117e4d490ced6d7931ad0ebdd8b49db3bd Mon Sep 17 00:00:00 2001 From: SoftFever Date: Tue, 13 Feb 2024 16:23:34 +0800 Subject: [PATCH] skip .stl/.png file when copying system profiles --- src/libslic3r/Utils.hpp | 2 +- src/libslic3r/utils.cpp | 4 +++- src/slic3r/Utils/PresetUpdater.cpp | 23 +++++++++++++++++++++-- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/libslic3r/Utils.hpp b/src/libslic3r/Utils.hpp index 0c7426a0ad..b03f27d187 100644 --- a/src/libslic3r/Utils.hpp +++ b/src/libslic3r/Utils.hpp @@ -654,7 +654,7 @@ inline std::string filter_characters(const std::string& str, const std::string& return filteredStr; } -void copy_directory_recursively(const boost::filesystem::path &source, const boost::filesystem::path &target); +void copy_directory_recursively(const boost::filesystem::path &source, const boost::filesystem::path &target, std::function filter = nullptr); // Orca: Since 1.7.9 Boost deprecated save_string_file and load_string_file, copy and modified from boost 1.7.8 void save_string_file(const boost::filesystem::path& p, const std::string& str); diff --git a/src/libslic3r/utils.cpp b/src/libslic3r/utils.cpp index dae1c13e5a..120a6f9ffc 100644 --- a/src/libslic3r/utils.cpp +++ b/src/libslic3r/utils.cpp @@ -1509,7 +1509,7 @@ bool bbl_calc_md5(std::string &filename, std::string &md5_out) } // SoftFever: copy directory recursively -void copy_directory_recursively(const boost::filesystem::path &source, const boost::filesystem::path &target) +void copy_directory_recursively(const boost::filesystem::path &source, const boost::filesystem::path &target, std::function filter) { BOOST_LOG_TRIVIAL(info) << Slic3r::format("copy_directory_recursively %1% -> %2%", source, target); std::string error_message; @@ -1528,6 +1528,8 @@ void copy_directory_recursively(const boost::filesystem::path &source, const boo copy_directory_recursively(dir_entry, target_path); } else { + if(filter && filter(name)) + continue; CopyFileResult cfr = copy_file(source_file, target_file, error_message, false); if (cfr != CopyFileResult::SUCCESS) { BOOST_LOG_TRIVIAL(error) << "Copying failed(" << cfr << "): " << error_message; diff --git a/src/slic3r/Utils/PresetUpdater.cpp b/src/slic3r/Utils/PresetUpdater.cpp index 3ec79d17f2..2c22465d43 100644 --- a/src/slic3r/Utils/PresetUpdater.cpp +++ b/src/slic3r/Utils/PresetUpdater.cpp @@ -1,6 +1,7 @@ #include "PresetUpdater.hpp" #include +#include #include #include #include @@ -80,6 +81,8 @@ struct Update //BBS: use changelog string instead of url std::string change_log; std::string descriptions; + // Orca: add file filter support + std::function file_filter; bool forced_update; //BBS: add directory support @@ -99,11 +102,23 @@ struct Update , is_directory(is_dir) {} + Update(fs::path &&source, fs::path &&target, const Version &version, std::string vendor, std::string changelog, std::string description, std::function file_filter, bool forced = false, bool is_dir = false) + : source(std::move(source)) + , target(std::move(target)) + , version(version) + , vendor(std::move(vendor)) + , change_log(std::move(changelog)) + , descriptions(std::move(description)) + , file_filter(file_filter) + , forced_update(forced) + , is_directory(is_dir) + {} + //BBS: add directory support void install() const { if (is_directory) { - copy_directory_recursively(source, target); + copy_directory_recursively(source, target, file_filter); } else { copy_file_fix(source, target); @@ -1066,7 +1081,11 @@ bool PresetUpdater::priv::install_bundles_rsrc(std::vector bundles, if (fs::exists(print_folder)) fs::remove_all(print_folder); fs::create_directories(print_folder); - updates.updates.emplace_back(std::move(print_in_rsrc), std::move(print_in_vendors), Version(), bundle, "", "", false, true); + updates.updates.emplace_back(std::move(print_in_rsrc), std::move(print_in_vendors), Version(), bundle, "", "",[](const std::string name){ + // return false if name is end with .stl, case insensitive + return boost::iends_with(name, ".stl") || boost::iends_with(name, ".png") || boost::iends_with(name, ".svg") || + boost::iends_with(name, ".jpeg") || boost::iends_with(name, ".jpg") || boost::iends_with(name, ".3mf"); + }, false, true); } return perform_updates(std::move(updates), snapshot);