OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::VendorCacheFile Class Reference

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

Static Public Member Functions

static bool save (const std::string &path, const std::string &vendor_name, const std::string &vendor_version, const VendorCacheData &data)
static bool load (const std::string &path, const std::string &expected_vendor_name, const Semver &expected_vendor_version, VendorCacheData &data)
static bool load_vendor_profile (const std::string &path, const std::string &expected_vendor_name, const Semver &expected_vendor_version, VendorProfile &vendor)
static std::string peek_version (const std::string &path, const std::string &expected_vendor_name)
static Semver usable_version (const std::string &path, const std::string &expected_vendor_name)
static bool carries_preset (const std::string &path, const std::string &vendor_name, Preset::Type type, const std::string &preset_name)

Detailed Description

Member Function Documentation

◆ carries_preset()

bool Slic3r::VendorCacheFile::carries_preset ( const std::string & path,
const std::string & vendor_name,
Preset::Type type,
const std::string & preset_name )
static
571{
572 std::string blob;
573 if (! read_cache_blob(path, blob))
574 return false;
575 try {
576 boost::iostreams::stream<boost::iostreams::array_source> body(blob.data(), blob.size());
577 cereal::BinaryInputArchive ar(body);
578 if (read_cache_stamps(ar, vendor_name).empty())
579 return false;
580 CacheDictionary dict;
581 dict.load(ar);
582 VendorMap vendors;
583 ar(vendors);
584 // Reused: every entry overwrites it, and only its name is ever looked at.
585 CachedPreset entry;
586 // Written in this order by save. The list that could carry the preset
587 // is the last one worth reading.
589 uint32_t cnt = 0;
590 ar(cnt);
591 for (uint32_t i = 0; i < cnt; ++ i) {
592 visit_entry(ar, entry, [&] { skip_config(ar, dict); });
593 if (kind == type && entry.name == preset_name)
594 return true;
595 }
596 if (kind == type)
597 return false;
598 }
599 return false;
600 } catch (const std::exception& e) {
601 BOOST_LOG_TRIVIAL(warning) << "VendorCacheFile: could not read preset names from " << path << ": " << e.what();
602 return false;
603 }
604}
Type
Definition Preset.hpp:244
@ TYPE_PRINTER
Definition Preset.hpp:250
@ TYPE_PRINT
Definition Preset.hpp:246
@ TYPE_FILAMENT
Definition Preset.hpp:248
bool read_cache_blob(const std::string &path, std::string &out_blob)
Definition PresetCacheFormat.cpp:376
std::string read_cache_stamps(cereal::BinaryInputArchive &ar, const std::string &expected_vendor_name)
Definition PresetCacheFormat.cpp:297
void visit_entry(Archive &ar, Entry &e, ConfigFn &&config)
Definition PresetCacheFormat.cpp:340
void skip_config(cereal::BinaryInputArchive &ar, const CacheDictionary &dict)
Definition PresetCacheFormat.cpp:247
std::map< std::string, VendorProfile > VendorMap
Definition Preset.hpp:238
bool empty(const BoundingBoxBase< PointType, PointsType > &bb)
Definition BoundingBox.hpp:273

References Slic3r::empty(), Slic3r::CacheDictionary::load(), Slic3r::CachedPreset::name, Slic3r::skip_config(), Slic3r::Preset::TYPE_FILAMENT, Slic3r::Preset::TYPE_PRINT, and Slic3r::Preset::TYPE_PRINTER.

Referenced by Slic3r::PresetBundle::find_preset_vendor().

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

◆ load()

bool Slic3r::VendorCacheFile::load ( const std::string & path,
const std::string & expected_vendor_name,
const Semver & expected_vendor_version,
VendorCacheData & data )
static
507{
508 return read_cache_up_to_presets(path, expected_vendor_name, expected_vendor_version, data.vendors,
509 [&data](cereal::BinaryInputArchive& ar, const CacheDictionary& dict) {
510 load_entries(ar, data.process_entries, dict);
511 load_entries(ar, data.filament_entries, dict);
512 load_entries(ar, data.machine_entries, dict);
513 ar(data.parse_errors);
514 });
515}
static bool read_cache_up_to_presets(const std::string &path, const std::string &expected_vendor_name, const Semver &expected_vendor_version, VendorMap &vendors, ReadRest &&read_rest)
Definition PresetCacheFormat.cpp:477

References Slic3r::read_cache_up_to_presets(), and Slic3r::VendorCacheData::vendors.

Referenced by Slic3r::PresetBundle::load_vendor_cache(), and Slic3r::PresetBundle::read_vendor().

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

◆ load_vendor_profile()

bool Slic3r::VendorCacheFile::load_vendor_profile ( const std::string & path,
const std::string & expected_vendor_name,
const Semver & expected_vendor_version,
VendorProfile & vendor )
static
520{
521 VendorMap vendors;
522 if (! read_cache_up_to_presets(path, expected_vendor_name, expected_vendor_version, vendors,
523 [](cereal::BinaryInputArchive&, const CacheDictionary&) {}))
524 return false;
525 vendor = std::move(vendors.find(expected_vendor_name)->second);
526 return true;
527}

References Slic3r::read_cache_up_to_presets().

Referenced by Slic3r::PresetBundle::read_vendor().

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

◆ peek_version()

std::string Slic3r::VendorCacheFile::peek_version ( const std::string & path,
const std::string & expected_vendor_name )
static
531{
532 try {
533 boost::nowide::ifstream ifs(path, std::ios::binary);
534 CacheFileHeader fhdr;
535 if (! ifs.read(reinterpret_cast<char*>(&fhdr), sizeof(fhdr)) || fhdr.magic != CACHE_MAGIC)
536 return {};
537 // Only the head of the body is read, and its CRC left unverified: the
538 // stamps sit at the front, and this answers "what version is this?"
539 // without paying for tens of megabytes. Callers that need to know the
540 // file is whole use usable_version instead.
541 std::string head(static_cast<size_t>(std::min<uint64_t>(fhdr.data_size, 1024)), '\0');
542 if (! ifs.read(&head[0], static_cast<std::streamsize>(head.size())))
543 return {};
544 std::istringstream body(head, std::ios::binary);
545 cereal::BinaryInputArchive ar(body);
546 return read_cache_stamps(ar, expected_vendor_name);
547 } catch (const std::exception&) {
548 return {};
549 }
550}

Referenced by Slic3r::GUI::GuideFrame::BuildProfileDataFromVendors(), and Slic3r::installable_cache_version().

Here is the caller graph for this function:

◆ save()

bool Slic3r::VendorCacheFile::save ( const std::string & path,
const std::string & vendor_name,
const std::string & vendor_version,
const VendorCacheData & data )
static
446{
447 try {
448 // Collected before anything is written: the dictionary sits ahead of the
449 // entries so a reader resolves it once and then indexes.
450 CacheDictionary dict;
451 for (const std::vector<CachedPreset>* entries : { &data.process_entries, &data.filament_entries, &data.machine_entries })
452 for (const CachedPreset& e : *entries)
453 dict.collect(e.config_src);
454
455 std::ostringstream body(std::ios::binary);
456 {
457 cereal::BinaryOutputArchive ar(body);
458 ar(CACHE_VERSION);
459 ar(vendor_name, vendor_version);
460 dict.save(ar);
461 ar(data.vendors);
462 save_entries(ar, data.process_entries, dict);
463 save_entries(ar, data.filament_entries, dict);
464 save_entries(ar, data.machine_entries, dict);
465 ar(data.parse_errors);
466 }
467 return write_cache_blob(path, body.str());
468 } catch (const std::exception& e) {
469 BOOST_LOG_TRIVIAL(warning) << "VendorCacheFile: failed to save vendor cache " << path << ": " << e.what();
470 return false;
471 }
472}
bool write_cache_blob(const std::string &path, const std::string &blob)
Definition PresetCacheFormat.cpp:415
void save_entries(cereal::BinaryOutputArchive &ar, const std::vector< CachedPreset > &entries, const CacheDictionary &dict)
Definition PresetCacheFormat.cpp:351

References Slic3r::CacheDictionary::collect(), Slic3r::VendorCacheData::filament_entries, Slic3r::VendorCacheData::machine_entries, Slic3r::VendorCacheData::parse_errors, Slic3r::VendorCacheData::process_entries, Slic3r::CacheDictionary::save(), and Slic3r::VendorCacheData::vendors.

Referenced by Slic3r::PresetBundle::install_vendor_read().

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

◆ usable_version()

Semver Slic3r::VendorCacheFile::usable_version ( const std::string & path,
const std::string & expected_vendor_name )
static
554{
555 std::string blob;
556 if (! read_cache_blob(path, blob))
557 return Semver::invalid();
558 try {
559 boost::iostreams::stream<boost::iostreams::array_source> body(blob.data(), blob.size());
560 cereal::BinaryInputArchive ar(body);
561 const auto ver = Semver::parse(read_cache_stamps(ar, expected_vendor_name));
562 return ver ? *ver : Semver::invalid();
563 } catch (const std::exception&) {
564 return Semver::invalid();
565 }
566}
static const Semver invalid()
Definition Semver.hpp:81
static boost::optional< Semver > parse(const std::string &str)
Definition Semver.hpp:63

References Slic3r::Semver::invalid(), and Slic3r::Semver::parse().

Referenced by Slic3r::PresetUpdater::priv::get_config_updates(), Slic3r::install_vendor_bundles_from_resources(), Slic3r::installed_vendor_version(), and Slic3r::is_vendor_installed().

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

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