OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::BundleMetadata Struct Reference

#include </home/runner/work/OrcaSlicer/OrcaSlicer/src/libslic3r/PresetBundle.hpp>

Collaboration diagram for Slic3r::BundleMetadata:

Public Member Functions

bool load_from_json (const std::string &path)
bool save_to_json (const std::string &path) const

Public Attributes

std::string id
std::string name
std::string version
std::string description
std::string author
long long imported_time {0}
long long updated_time {0}
BundleType bundle_type {Default}
std::string path
std::vector< std::string > print_presets
std::vector< std::string > filament_presets
std::vector< std::string > printer_presets
bool is_subscribed {false}
bool update_available {false}
bool not_found {false}
bool unauthorized {false}

Detailed Description

Member Function Documentation

◆ load_from_json()

bool Slic3r::BundleMetadata::load_from_json ( const std::string & path)
9021{
9022 try {
9023 boost::nowide::ifstream ifs(path);
9024 if (!ifs.good())
9025 return false;
9026
9027 json j;
9028 ifs >> j;
9029
9030 if (j.contains("id")) this->id = j["id"].get<std::string>();
9031
9032 if (j.contains("name")) this->name = j["name"].get<std::string>();
9033 else if (j.contains("bundle_id")) this->name = j["bundle_id"].get<std::string>(); // backwards compat w bundle_structure.json
9034
9035 if (j.contains("version")) this->version = j["version"].get<std::string>();
9036
9037 if (j.contains("description")) this->description = j["description"].get<std::string>();
9038 else if (j.contains("bundle_type")) this->description = j["bundle_type"].get<std::string>(); // backwards compat w bundle_structure.json
9039
9040 if (j.contains("author")) this->author = j["author"].get<std::string>();
9041
9042 if (j.contains("imported_time")) this->imported_time = j["imported_time"].get<long long>();
9043
9044 if (j.contains("updated_time")) this->updated_time = j["updated_time"].get<long long>();
9045
9046 if (j.contains("print_presets"))
9047 this->print_presets = j["print_presets"].get<std::vector<std::string>>();
9048
9049 if (j.contains("filament_presets"))
9050 this->filament_presets = j["filament_presets"].get<std::vector<std::string>>();
9051
9052 if (j.contains("printer_presets"))
9053 this->printer_presets = j["printer_presets"].get<std::vector<std::string>>();
9054
9055 return true;
9056 } catch (const std::exception& e) {
9057 BOOST_LOG_TRIVIAL(error) << "Failed to load bundle metadata from " << path << ": " << e.what();
9058 return false;
9059 }
9060}
nlohmann::json json
Definition AssembleList.cpp:42
std::vector< std::string > printer_presets
Definition PresetBundle.hpp:134
std::string description
Definition PresetBundle.hpp:123
std::vector< std::string > print_presets
Definition PresetBundle.hpp:132
std::string name
Definition PresetBundle.hpp:121
std::vector< std::string > filament_presets
Definition PresetBundle.hpp:133
std::string version
Definition PresetBundle.hpp:122
std::string path
Definition PresetBundle.hpp:129
long long imported_time
Definition PresetBundle.hpp:125
long long updated_time
Definition PresetBundle.hpp:126
std::string author
Definition PresetBundle.hpp:124

References author, description, filament_presets, imported_time, load_from_json(), name, path, print_presets, printer_presets, updated_time, and version.

Referenced by Slic3r::check_local_bundle(), Slic3r::PresetBundle::import_presets(), and load_from_json().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ save_to_json()

bool Slic3r::BundleMetadata::save_to_json ( const std::string & path) const
9063{
9064 auto strip_prefix = [](const std::vector<std::string>& names) {
9065 json arr = json::array();
9066 for (const auto& name : names)
9067 {
9068 arr.push_back(boost::filesystem::path(name).filename().string());
9069 std::string test = boost::filesystem::path(name).filename().string();
9070 }
9071 return arr;
9072 };
9073 try {
9074 json j;
9075 j["id"] = this->id;
9076 j["name"] = this->name;
9077 j["version"] = this->version;
9078 j["description"] = this->description;
9079 j["author"] = this->author;
9080 j["imported_time"] = this->imported_time;
9081 j["updated_time"] = this->updated_time;
9082
9083 j["print_presets"] = strip_prefix(this->print_presets);
9084 j["filament_presets"] = strip_prefix(this->filament_presets);
9085 j["printer_presets"] = strip_prefix(this->printer_presets);
9086
9087 const std::string content = j.dump(4);
9088 InstanceLock instance_lock(user_presets_lock_path());
9089 if (const std::error_code ec = write_file_atomically(path, content)) {
9090 BOOST_LOG_TRIVIAL(error) << "Failed to save bundle metadata to " << path << ": " << ec.message();
9091 return false;
9092 }
9093 return true;
9094 } catch (const std::exception& e) {
9095 BOOST_LOG_TRIVIAL(error) << "Failed to save bundle metadata to " << path << ": " << e.what();
9096 return false;
9097 }
9098}
std::string user_presets_lock_path(bool read_only)
Definition Preset.cpp:146
std::error_code write_file_atomically(const std::string &path, std::initializer_list< std::string_view > chunks, bool binary)
Definition utils.cpp:796
std::string id
Definition PresetBundle.hpp:120

References author, description, filament_presets, id, imported_time, name, path, print_presets, printer_presets, save_to_json(), updated_time, Slic3r::user_presets_lock_path(), version, and Slic3r::write_file_atomically().

Referenced by Slic3r::PresetBundle::import_presets(), and save_to_json().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ author

◆ bundle_type

◆ description

◆ filament_presets

std::vector<std::string> Slic3r::BundleMetadata::filament_presets

◆ id

◆ imported_time

long long Slic3r::BundleMetadata::imported_time {0}

◆ is_subscribed

◆ name

◆ not_found

bool Slic3r::BundleMetadata::not_found {false}
139{false};

◆ path

◆ print_presets

std::vector<std::string> Slic3r::BundleMetadata::print_presets

◆ printer_presets

std::vector<std::string> Slic3r::BundleMetadata::printer_presets

◆ unauthorized

bool Slic3r::BundleMetadata::unauthorized {false}

◆ update_available

bool Slic3r::BundleMetadata::update_available {false}

◆ updated_time

long long Slic3r::BundleMetadata::updated_time {0}

◆ version


The documentation for this struct was generated from the following files: