fix(preset): filament_id in Preset::save() generieren statt nur in save_current_preset()

Der vorherige Fix griff nur beim Umbenennen. Beim normalen Speichern
läuft Preset::save() — dort wird jetzt ebenfalls eine MD5-basierte ID
generiert wenn das User-Filament-Preset noch keine hat.
This commit is contained in:
viewit
2026-06-02 18:33:17 +02:00
parent 51aec8637c
commit bb7497cf26

View File

@@ -638,6 +638,23 @@ void Preset::save(DynamicPrintConfig* parent_config)
//BBS: add project embedded preset logic
if (this->is_project_embedded)
return;
// Generate a unique filament_id for user filament presets that don't have one yet.
// Inherited presets (e.g. "My PLA" inheriting "Generic PLA @System") previously had
// no filament_id which caused AMS sync to fall back to the parent's Generic ID.
if (this->is_user() && this->filament_id.empty() && !this->name.empty() &&
this->type() == Preset::TYPE_FILAMENT) {
boost::uuids::detail::md5 hash;
boost::uuids::detail::md5::digest_type digest;
hash.process_bytes(this->name.data(), this->name.size());
hash.get_digest(digest);
const auto char_digest = reinterpret_cast<const char *>(&digest);
std::string result;
boost::algorithm::hex(char_digest, char_digest + sizeof(boost::uuids::detail::md5::digest_type), std::back_inserter(result));
this->filament_id = "P" + result.substr(0, 7);
BOOST_LOG_TRIVIAL(info) << "Preset::save: generated filament_id='" << this->filament_id << "' for user preset '" << this->name << "'";
}
//BBS: change to json format
//this->config.save(this->file);
std::string from_str;