diff --git a/src/BambuStudio.cpp b/src/BambuStudio.cpp index 1197e0ced5..2cf7e053ec 100644 --- a/src/BambuStudio.cpp +++ b/src/BambuStudio.cpp @@ -311,11 +311,17 @@ static PrinterTechnology get_printer_technology(const DynamicConfig &config) g_cli_callback_mgr.stop();\ boost::nowide::cout.flush();\ boost::nowide::cerr.flush();\ + for (Model &model : m_models) {\ + model.remove_backup_path_if_exist();\ + }\ return(ret);} #else #define flush_and_exit(ret) { boost::nowide::cout << __FUNCTION__ << " found error, exit" << std::endl;\ boost::nowide::cout.flush();\ boost::nowide::cerr.flush();\ + for (Model &model : m_models) {\ + model.remove_backup_path_if_exist();\ + }\ return(ret);} #endif @@ -2371,6 +2377,9 @@ int CLI::run(int argc, char **argv) g_cli_callback_mgr.stop(); #endif + for (Model &model : m_models) { + model.remove_backup_path_if_exist(); + } //BBS: flush logs BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ", Finished" << std::endl; boost::nowide::cout.flush(); diff --git a/src/libslic3r/Model.cpp b/src/libslic3r/Model.cpp index cff60e72ce..d710efd742 100644 --- a/src/libslic3r/Model.cpp +++ b/src/libslic3r/Model.cpp @@ -790,9 +790,11 @@ std::string Model::get_backup_path() buf << this->id().id; backup_path = parent_path.string() + buf.str(); + BOOST_LOG_TRIVIAL(info) << boost::format("model %1%, id %2%, backup_path empty, set to %3%")%this%this->id().id%backup_path; boost::filesystem::path temp_path(backup_path); if (boost::filesystem::exists(temp_path)) { + BOOST_LOG_TRIVIAL(info) << boost::format("model %1%, id %2%, remove previous %3%")%this%this->id().id%backup_path; boost::filesystem::remove_all(temp_path); } } @@ -815,6 +817,19 @@ std::string Model::get_backup_path() return backup_path; } +void Model::remove_backup_path_if_exist() +{ + if (!backup_path.empty()) { + boost::filesystem::path temp_path(backup_path); + if (boost::filesystem::exists(temp_path)) + { + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format("model %1%, id %2% remove backup_path %3%")%this%this->id().id%backup_path; + boost::filesystem::remove_all(temp_path); + } + backup_path.clear(); + } +} + std::string Model::get_backup_path(const std::string &sub_path) { auto path = get_backup_path() + "/" + sub_path; @@ -837,9 +852,12 @@ void Model::set_backup_path(std::string const& path) backup_path.clear(); return; } - if (!backup_path.empty()) + if (!backup_path.empty()) { + BOOST_LOG_TRIVIAL(info) << __FUNCTION__<id().id%backup_path; Slic3r::remove_backup(*this, true); + } backup_path = path; + BOOST_LOG_TRIVIAL(info) << __FUNCTION__<id().id%backup_path; } void Model::load_from(Model& model) diff --git a/src/libslic3r/Model.hpp b/src/libslic3r/Model.hpp index c682af16c0..d12bf1f7d9 100644 --- a/src/libslic3r/Model.hpp +++ b/src/libslic3r/Model.hpp @@ -1433,6 +1433,7 @@ public: void load_from(Model & model); bool is_need_backup() { return need_backup; } void set_need_backup(); + void remove_backup_path_if_exist(); // Checks if any of objects is painted using the fdm support painting gizmo. bool is_fdm_support_painted() const;