diff --git a/src/libslic3r/PrintExport.hpp b/src/libslic3r/PrintExport.hpp index 9561e57718..1b5efcea11 100644 --- a/src/libslic3r/PrintExport.hpp +++ b/src/libslic3r/PrintExport.hpp @@ -266,6 +266,8 @@ public: m_layers_rst[i].rawbytes.size()); } } + + writer.close(); } catch(std::exception& e) { BOOST_LOG_TRIVIAL(error) << e.what(); // Rethrow the exception diff --git a/src/libslic3r/SLAPrint.hpp b/src/libslic3r/SLAPrint.hpp index 0b72a3abb6..dfaa2bff50 100644 --- a/src/libslic3r/SLAPrint.hpp +++ b/src/libslic3r/SLAPrint.hpp @@ -231,7 +231,7 @@ public: return true; // m_zip blows up if something goes wrong... } - inline void close() { /* m_zip closes upon destruction */ } + inline void close() { m_zip.close(); } }; /** diff --git a/src/libslic3r/Zipper.cpp b/src/libslic3r/Zipper.cpp index a318d659ad..490805c0dd 100644 --- a/src/libslic3r/Zipper.cpp +++ b/src/libslic3r/Zipper.cpp @@ -5,6 +5,7 @@ #include "Zipper.hpp" #include "miniz/miniz_zip.h" #include +#include #include "I18N.hpp" @@ -25,7 +26,7 @@ public: mz_zip_archive arch; std::string m_zipname; - std::string get_errorstr(mz_zip_error mz_err) + static std::string get_errorstr(mz_zip_error mz_err) { switch (mz_err) { @@ -100,10 +101,15 @@ public: return "unknown error"; } - SLIC3R_NORETURN void blow_up() { - std::string prefix(L("Error with zip archive")); - throw std::runtime_error(prefix + " " + m_zipname + ": " + - get_errorstr(arch.m_last_error) + "!"); + std::string formatted_errorstr() const + { + return L("Error with zip archive") + " " + m_zipname + ": " + + get_errorstr(arch.m_last_error) + "!"; + } + + SLIC3R_NORETURN void blow_up() const + { + throw std::runtime_error(formatted_errorstr()); } }; @@ -123,10 +129,11 @@ Zipper::Zipper(const std::string &zipfname, e_compression compression) Zipper::~Zipper() { - finish_entry(); - - if(!mz_zip_writer_finalize_archive(&m_impl->arch)) m_impl->blow_up(); - if(!mz_zip_writer_end(&m_impl->arch)) m_impl->blow_up(); + try { + close(); + } catch(...) { + BOOST_LOG_TRIVIAL(error) << m_impl->formatted_errorstr(); + } } Zipper::Zipper(Zipper &&m): @@ -191,4 +198,12 @@ std::string Zipper::get_name() const { return boost::filesystem::path(m_impl->m_zipname).stem().string(); } +void Zipper::close() +{ + finish_entry(); + + if(!mz_zip_writer_finalize_archive(&m_impl->arch)) m_impl->blow_up(); + if(!mz_zip_writer_end(&m_impl->arch)) m_impl->blow_up(); +} + } diff --git a/src/libslic3r/Zipper.hpp b/src/libslic3r/Zipper.hpp index a7b0c6e7fd..7319c4ac4e 100644 --- a/src/libslic3r/Zipper.hpp +++ b/src/libslic3r/Zipper.hpp @@ -78,6 +78,8 @@ public: /// Gets the name of the archive without the path or extension. std::string get_name() const; + + void close(); };