remove retired_filament_ids.json

This commit is contained in:
SoftFever
2026-09-03 21:03:42 +08:00
parent fdc0ee18f1
commit 7c9b38ba04
16 changed files with 119 additions and 8309 deletions

View File

@@ -572,60 +572,6 @@ std::string generate_preset_setting_id(const std::string& vendor, const std::str
return std::string(out, 16);
}
std::string follow_filament_id_succession(const std::string& id, const std::map<std::string, std::string>& forwards)
{
auto it = forwards.find(id);
if (it == forwards.end())
return std::string();
std::set<std::string> visited { id };
std::string current = id;
while (it != forwards.end() && visited.insert(it->second).second) {
current = it->second;
it = forwards.find(current);
}
// it == end(): current is the live end of the chain; otherwise the ledger is
// cyclic and current is the last id reached before a repeat.
return current;
}
const std::map<std::string, std::string>& filament_id_succession_map()
{
// Loaded once; C++11 magic-static initialization makes this thread-safe.
// Succession is a best-effort miss-path fallback, so a missing or corrupt
// ledger is not an error for the client - it just yields an empty map.
static const std::map<std::string, std::string> forwards = []() {
std::map<std::string, std::string> map;
const std::string path = Slic3r::resources_dir() + "/profiles/retired_filament_ids.json";
boost::nowide::ifstream file(path.c_str());
if (!file.is_open()) {
BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << ": cannot open " << path;
return map;
}
try {
nlohmann::json ledger;
file >> ledger;
if (ledger.contains("retired") && ledger["retired"].is_object())
for (auto& [old_id, entry] : ledger["retired"].items())
if (entry.is_object() && entry.contains("successor") && entry["successor"].is_string())
map[old_id] = entry["successor"].get<std::string>();
if (ledger.contains("hints") && ledger["hints"].is_object())
for (auto& [old_id, target] : ledger["hints"].items())
if (target.is_string())
map[old_id] = target.get<std::string>();
} catch (...) {
BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << ": failed to parse " << path;
map.clear();
}
return map;
}();
return forwards;
}
std::string resolve_filament_id_succession(const std::string& id)
{
return follow_filament_id_succession(id, filament_id_succession_map());
}
std::string Preset::get_iot_type_string(Preset::Type type)
{
switch (type) {

View File

@@ -101,23 +101,6 @@ std::string generate_preset_setting_id(const std::string& vendor,
const std::string& type,
const std::string& name);
// Succession forwarding for retired/renamed filament_ids, backed by the shipped
// ledger resources/profiles/retired_filament_ids.json. Consulted on a filament_id
// resolution miss only, so live ids always resolve natively first.
//
// Pure chain walk over `forwards` (old id -> successor). Returns the final id of the
// chain, or an empty string when `id` has no entry. Cycle-guarded: on a malformed
// cyclic ledger it stops at the last id reached before any repeat (a self-loop
// returns `id` itself).
std::string follow_filament_id_succession(const std::string& id,
const std::map<std::string, std::string>& forwards);
// Forwarding map loaded once (thread-safe) from the ledger, merging
// "retired" {id -> non-null successor} and "hints" {island-owned id -> live id}.
// A missing or corrupt file yields an empty map.
const std::map<std::string, std::string>& filament_id_succession_map();
// Convenience: follow_filament_id_succession(id, filament_id_succession_map()).
std::string resolve_filament_id_succession(const std::string& id);
enum ConfigFileType
{
CONFIG_FILE_TYPE_UNKNOWN,

View File

@@ -801,12 +801,6 @@ std::optional<FilamentBaseInfo> PresetBundle::get_filament_by_filament_id(const
}
}
}
// Miss: a retired/renamed id may forward to a live successor through the shipped
// succession ledger. resolve() returns a chain-final id, so the retry below cannot
// recurse further (a malformed cyclic ledger yields a non-final id, rejected here).
const std::string successor = resolve_filament_id_succession(filament_id);
if (!successor.empty() && resolve_filament_id_succession(successor).empty())
return get_filament_by_filament_id(successor, printer_name);
return std::nullopt;
}
@@ -3420,15 +3414,6 @@ void PresetBundle::get_ams_cobox_infos(AMSComboInfo& combox_info)
auto iter = std::find_if(filaments.begin(), filaments.end(),
[this, &filament_id](auto &f) { return f.is_compatible && filaments.get_preset_base(f) == &f && f.filament_id == filament_id; });
warn_ambiguous_filament_id_match(filaments, iter, filament_id);
if (iter == filaments.end()) {
// Retired/renamed ids forward to a live successor through the shipped succession ledger.
const std::string successor = resolve_filament_id_succession(filament_id);
if (!successor.empty()) {
iter = std::find_if(filaments.begin(), filaments.end(),
[this, &successor](auto &f) { return f.is_compatible && filaments.get_preset_base(f) == &f && f.filament_id == successor; });
warn_ambiguous_filament_id_match(filaments, iter, successor);
}
}
if (iter == filaments.end()) {
BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(": filament_id %1% not found or system or compatible") % filament_id;
auto filament_type = ams.opt_string("filament_type", 0u);
@@ -3532,16 +3517,6 @@ unsigned int PresetBundle::sync_ams_list(std::vector<std::pair<DynamicPrintConfi
has_type |= f.config.opt_string("filament_type", 0u) == filament_type;
return f.is_compatible && filaments.get_preset_base(f) == &f && f.filament_id == filament_id; });
warn_ambiguous_filament_id_match(filaments, iter, filament_id);
if (iter == filaments.end()) {
// Retired/renamed ids forward to a live successor through the shipped succession
// ledger (has_type is already complete: the miss above scanned every preset).
const std::string successor = resolve_filament_id_succession(filament_id);
if (!successor.empty()) {
iter = std::find_if(filaments.begin(), filaments.end(), [this, &successor](auto &f) {
return f.is_compatible && filaments.get_preset_base(f) == &f && f.filament_id == successor; });
warn_ambiguous_filament_id_match(filaments, iter, successor);
}
}
if (iter == filaments.end()) {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": filament_id %1% not found or system or compatible") % filament_id;
if (!filament_type.empty()) {