mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-23 06:33:57 -06:00
Adjust miniz usage to use nowide FILE streams everywhere.
This commit is contained in:
parent
15620a2fc2
commit
460887cdde
4 changed files with 83 additions and 34 deletions
|
@ -13,6 +13,7 @@
|
|||
#include <boost/algorithm/string/predicate.hpp>
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
#include <boost/nowide/fstream.hpp>
|
||||
#include <boost/nowide/cstdio.hpp>
|
||||
|
||||
#include <expat.h>
|
||||
#include <Eigen/Dense>
|
||||
|
@ -187,6 +188,24 @@ bool is_valid_object_type(const std::string& type)
|
|||
|
||||
namespace Slic3r {
|
||||
|
||||
namespace {
|
||||
void close_archive_reader(mz_zip_archive *arch) {
|
||||
if (arch) {
|
||||
FILE *f = mz_zip_get_cfile(arch);
|
||||
mz_zip_reader_end(arch);
|
||||
if (f) fclose(f);
|
||||
}
|
||||
}
|
||||
|
||||
void close_archive_writer(mz_zip_archive *arch) {
|
||||
if (arch) {
|
||||
FILE *f = mz_zip_get_cfile(arch);
|
||||
mz_zip_writer_end(arch);
|
||||
if (f) fclose(f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Base class with error messages management
|
||||
class _3MF_Base
|
||||
{
|
||||
|
@ -502,8 +521,9 @@ namespace Slic3r {
|
|||
{
|
||||
mz_zip_archive archive;
|
||||
mz_zip_zero_struct(&archive);
|
||||
|
||||
mz_bool res = mz_zip_reader_init_file(&archive, filename.c_str(), 0);
|
||||
|
||||
FILE *f = boost::nowide::fopen(filename.c_str(), "rb");
|
||||
auto res = mz_bool(f != nullptr && mz_zip_reader_init_cfile(&archive, f, -1, 0));
|
||||
if (res == 0)
|
||||
{
|
||||
add_error("Unable to open the file");
|
||||
|
@ -529,7 +549,7 @@ namespace Slic3r {
|
|||
// valid model name -> extract model
|
||||
if (!_extract_model_from_archive(archive, stat))
|
||||
{
|
||||
mz_zip_reader_end(&archive);
|
||||
close_archive_reader(&archive);
|
||||
add_error("Archive does not contain a valid model");
|
||||
return false;
|
||||
}
|
||||
|
@ -565,7 +585,7 @@ namespace Slic3r {
|
|||
// extract slic3r model config file
|
||||
if (!_extract_model_config_from_archive(archive, stat, model))
|
||||
{
|
||||
mz_zip_reader_end(&archive);
|
||||
close_archive_reader(&archive);
|
||||
add_error("Archive does not contain a valid model config");
|
||||
return false;
|
||||
}
|
||||
|
@ -573,7 +593,7 @@ namespace Slic3r {
|
|||
}
|
||||
}
|
||||
|
||||
mz_zip_reader_end(&archive);
|
||||
close_archive_reader(&archive);
|
||||
|
||||
for (const IdToModelObjectMap::value_type& object : m_objects)
|
||||
{
|
||||
|
@ -1639,7 +1659,8 @@ namespace Slic3r {
|
|||
mz_zip_archive archive;
|
||||
mz_zip_zero_struct(&archive);
|
||||
|
||||
mz_bool res = mz_zip_writer_init_file(&archive, filename.c_str(), 0);
|
||||
FILE *f = boost::nowide::fopen(filename.c_str(), "wb");
|
||||
auto res = mz_bool(f != nullptr && mz_zip_writer_init_cfile(&archive, f, 0));
|
||||
if (res == 0)
|
||||
{
|
||||
add_error("Unable to open the file");
|
||||
|
@ -1650,7 +1671,7 @@ namespace Slic3r {
|
|||
// The content of this file is the same for each PrusaSlicer 3mf.
|
||||
if (!_add_content_types_file_to_archive(archive))
|
||||
{
|
||||
mz_zip_writer_end(&archive);
|
||||
close_archive_writer(&archive);
|
||||
boost::filesystem::remove(filename);
|
||||
return false;
|
||||
}
|
||||
|
@ -1660,7 +1681,7 @@ namespace Slic3r {
|
|||
// The relationshis file contains a reference to the geometry file "3D/3dmodel.model", the name was chosen to be compatible with CURA.
|
||||
if (!_add_relationships_file_to_archive(archive))
|
||||
{
|
||||
mz_zip_writer_end(&archive);
|
||||
close_archive_writer(&archive);
|
||||
boost::filesystem::remove(filename);
|
||||
return false;
|
||||
}
|
||||
|
@ -1670,7 +1691,7 @@ namespace Slic3r {
|
|||
IdToObjectDataMap objects_data;
|
||||
if (!_add_model_file_to_archive(archive, model, objects_data))
|
||||
{
|
||||
mz_zip_writer_end(&archive);
|
||||
close_archive_writer(&archive);
|
||||
boost::filesystem::remove(filename);
|
||||
return false;
|
||||
}
|
||||
|
@ -1680,7 +1701,7 @@ namespace Slic3r {
|
|||
// The index differes from the index of an object ID of an object instance of a 3MF file!
|
||||
if (!_add_layer_height_profile_file_to_archive(archive, model))
|
||||
{
|
||||
mz_zip_writer_end(&archive);
|
||||
close_archive_writer(&archive);
|
||||
boost::filesystem::remove(filename);
|
||||
return false;
|
||||
}
|
||||
|
@ -1690,7 +1711,7 @@ namespace Slic3r {
|
|||
// The index differes from the index of an object ID of an object instance of a 3MF file!
|
||||
if (!_add_sla_support_points_file_to_archive(archive, model))
|
||||
{
|
||||
mz_zip_writer_end(&archive);
|
||||
close_archive_writer(&archive);
|
||||
boost::filesystem::remove(filename);
|
||||
return false;
|
||||
}
|
||||
|
@ -1701,7 +1722,7 @@ namespace Slic3r {
|
|||
{
|
||||
if (!_add_print_config_file_to_archive(archive, *config))
|
||||
{
|
||||
mz_zip_writer_end(&archive);
|
||||
close_archive_writer(&archive);
|
||||
boost::filesystem::remove(filename);
|
||||
return false;
|
||||
}
|
||||
|
@ -1713,20 +1734,20 @@ namespace Slic3r {
|
|||
// is stored here as well.
|
||||
if (!_add_model_config_file_to_archive(archive, model, objects_data))
|
||||
{
|
||||
mz_zip_writer_end(&archive);
|
||||
close_archive_writer(&archive);
|
||||
boost::filesystem::remove(filename);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!mz_zip_writer_finalize_archive(&archive))
|
||||
{
|
||||
mz_zip_writer_end(&archive);
|
||||
close_archive_writer(&archive);
|
||||
boost::filesystem::remove(filename);
|
||||
add_error("Unable to finalize the archive");
|
||||
return false;
|
||||
}
|
||||
|
||||
mz_zip_writer_end(&archive);
|
||||
close_archive_writer(&archive);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue