From 76290b08eff4b479db50ca4986ad46f224fb6869 Mon Sep 17 00:00:00 2001 From: "maosheng.wei" Date: Mon, 1 Apr 2024 09:24:31 +0800 Subject: [PATCH] FIX: structure json line break process when export configs Jira: XXXX Change-Id: I9b518d7363f51c39574a1e8733174ae6ad99f1c5 --- src/slic3r/GUI/CreatePresetsDialog.cpp | 15 +++++++++++++-- src/slic3r/GUI/CreatePresetsDialog.hpp | 2 ++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/slic3r/GUI/CreatePresetsDialog.cpp b/src/slic3r/GUI/CreatePresetsDialog.cpp index 6d22aa85e..96324204e 100644 --- a/src/slic3r/GUI/CreatePresetsDialog.cpp +++ b/src/slic3r/GUI/CreatePresetsDialog.cpp @@ -3617,6 +3617,17 @@ wxBoxSizer *ExportConfigsDialog::create_radio_item(wxString title, wxWindow *par return horizontal_sizer; } +std::string ExportConfigsDialog::create_structure_file(json & structure) +{ + if (structure.is_null()) return ""; + + ostringstream oss; + oss << std::setw(4) << structure << std::endl; + std::string bundle_structure = oss.str(); + + return bundle_structure; +} + mz_bool ExportConfigsDialog::initial_zip_archive(mz_zip_archive &zip_archive, const std::string &file_path) { mz_zip_zero_struct(&zip_archive); @@ -3865,7 +3876,7 @@ ExportConfigsDialog::ExportCase ExportConfigsDialog::archive_preset_bundle_to_fi bundle_structure["filament_config"] = filament_configs; bundle_structure["process_config"] = process_configs; - std::string bundle_structure_str = bundle_structure.dump(); + std::string bundle_structure_str = create_structure_file(bundle_structure); status = mz_zip_writer_add_mem(&zip_archive, BUNDLE_STRUCTURE_JSON_NAME, bundle_structure_str.data(), bundle_structure_str.size(), MZ_DEFAULT_COMPRESSION); if (MZ_FALSE == status) { BOOST_LOG_TRIVIAL(info) << " Failed to add file: " << BUNDLE_STRUCTURE_JSON_NAME; @@ -3960,7 +3971,7 @@ ExportConfigsDialog::ExportCase ExportConfigsDialog::archive_filament_bundle_to_ bundle_structure["printer_vendor"].push_back(j); } - std::string bundle_structure_str = bundle_structure.dump(); + std::string bundle_structure_str = create_structure_file(bundle_structure); status = mz_zip_writer_add_mem(&zip_archive, BUNDLE_STRUCTURE_JSON_NAME, bundle_structure_str.data(), bundle_structure_str.size(), MZ_DEFAULT_COMPRESSION); if (MZ_FALSE == status) { BOOST_LOG_TRIVIAL(info) << " Failed to add file: " << BUNDLE_STRUCTURE_JSON_NAME; diff --git a/src/slic3r/GUI/CreatePresetsDialog.hpp b/src/slic3r/GUI/CreatePresetsDialog.hpp index 9bb09c57d..532054cd5 100644 --- a/src/slic3r/GUI/CreatePresetsDialog.hpp +++ b/src/slic3r/GUI/CreatePresetsDialog.hpp @@ -12,6 +12,7 @@ #include "Widgets/ComboBox.hpp" #include "miniz.h" #include "ParamsDialog.hpp" +#include "json_diff.hpp" namespace Slic3r { namespace GUI { @@ -271,6 +272,7 @@ private: wxBoxSizer *create_button_item(wxWindow *parent); wxBoxSizer *create_select_printer(wxWindow *parent); wxBoxSizer *create_radio_item(wxString title, wxWindow *parent, wxString tooltip, std::vector> &radiobox_list); + std::string create_structure_file(json &structure); int initial_zip_archive(mz_zip_archive &zip_archive, const std::string &file_path); ExportCase save_zip_archive_to_file(mz_zip_archive &zip_archive); ExportCase save_presets_to_zip(const std::string &export_file, const std::vector> &config_paths);