mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-05-11 23:19:06 +08:00
Fix unclosed file after export.
This commit is contained in:
parent
916016f2d4
commit
15620a2fc2
@ -22,6 +22,7 @@ class Zipper::Impl {
|
|||||||
public:
|
public:
|
||||||
mz_zip_archive arch;
|
mz_zip_archive arch;
|
||||||
std::string m_zipname;
|
std::string m_zipname;
|
||||||
|
FILE *cfile = nullptr;
|
||||||
|
|
||||||
static std::string get_errorstr(mz_zip_error mz_err)
|
static std::string get_errorstr(mz_zip_error mz_err)
|
||||||
{
|
{
|
||||||
@ -124,15 +125,15 @@ Zipper::Zipper(const std::string &zipfname, e_compression compression)
|
|||||||
|
|
||||||
memset(&m_impl->arch, 0, sizeof(m_impl->arch));
|
memset(&m_impl->arch, 0, sizeof(m_impl->arch));
|
||||||
|
|
||||||
FILE *f = boost::nowide::fopen(zipfname.c_str(), "wb");
|
m_impl->cfile = boost::nowide::fopen(zipfname.c_str(), "wb");
|
||||||
|
|
||||||
if (f == nullptr) {
|
if (m_impl->cfile == nullptr) {
|
||||||
m_impl->arch.m_last_error = MZ_ZIP_FILE_OPEN_FAILED;
|
m_impl->arch.m_last_error = MZ_ZIP_FILE_OPEN_FAILED;
|
||||||
m_impl->blow_up();
|
m_impl->blow_up();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize the archive data
|
// Initialize the archive data
|
||||||
if(!mz_zip_writer_init_cfile(&m_impl->arch, f, 0))
|
if(!mz_zip_writer_init_cfile(&m_impl->arch, m_impl->cfile, 0))
|
||||||
m_impl->blow_up();
|
m_impl->blow_up();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,6 +152,8 @@ Zipper::~Zipper()
|
|||||||
// The file should be closed no matter what...
|
// The file should be closed no matter what...
|
||||||
if(!mz_zip_writer_end(&m_impl->arch))
|
if(!mz_zip_writer_end(&m_impl->arch))
|
||||||
BOOST_LOG_TRIVIAL(error) << m_impl->formatted_errorstr();
|
BOOST_LOG_TRIVIAL(error) << m_impl->formatted_errorstr();
|
||||||
|
|
||||||
|
if(m_impl->cfile) fclose(m_impl->cfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
Zipper::Zipper(Zipper &&m):
|
Zipper::Zipper(Zipper &&m):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user