Don't check the content of repetier server name

supermerill/SuperSlicer#1376
Also don't crash on identification error
This commit is contained in:
remi durand 2021-07-10 11:51:25 +02:00
parent 4d947212f4
commit d0c3cc5553
2 changed files with 34 additions and 27 deletions

View File

@ -271,31 +271,35 @@ void PhysicalPrinterDialog::update_printers()
wxArrayString printers;
Field* rs = m_optgroup->get_field("printhost_port");
if (!host->get_printers(printers)) {
std::vector<std::string> slugs;
try {
if (!host->get_printers(printers)) {
std::vector<std::string> slugs;
Choice* choice = dynamic_cast<Choice*>(rs);
choice->set_values(slugs);
Choice* choice = dynamic_cast<Choice*>(rs);
choice->set_values(slugs);
rs->disable();
} else {
std::vector<std::string> slugs;
for (int i = 0; i < printers.size(); i++) {
slugs.push_back(printers[i].ToStdString());
rs->disable();
} else {
std::vector<std::string> slugs;
for (int i = 0; i < printers.size(); i++) {
slugs.push_back(printers[i].ToStdString());
}
Choice* choice = dynamic_cast<Choice*>(rs);
choice->set_values(slugs);
boost::any val = choice->get_value();
boost::any any_string_type = std::string("");
auto value_idx = std::find(slugs.begin(), slugs.end(), m_config->opt<ConfigOptionString>("printhost_port")->value);
if ((val.empty() || (any_string_type.type() == val.type() && boost::any_cast<std::string>(val) == "")) && !slugs.empty() && value_idx == slugs.end()) {
change_opt_value(*m_config, "printhost_port", slugs[0]);
choice->set_value(slugs[0], false);
} else if (value_idx != slugs.end()) {
choice->set_value(m_config->option<ConfigOptionString>("printhost_port")->value, false);
}
rs->enable();
}
Choice* choice = dynamic_cast<Choice*>(rs);
choice->set_values(slugs);
boost::any val = choice->get_value();
boost::any any_string_type = std::string("");
auto value_idx = std::find(slugs.begin(), slugs.end(), m_config->opt<ConfigOptionString>("printhost_port")->value);
if ((val.empty() || (any_string_type.type() == val.type() && boost::any_cast<std::string>(val) == "")) && !slugs.empty() && value_idx == slugs.end()) {
change_opt_value(*m_config, "printhost_port", slugs[0]);
choice->set_value(slugs[0],false);
} else if(value_idx != slugs.end() ){
choice->set_value(m_config->option<ConfigOptionString>("printhost_port")->value, false);
}
rs->enable();
} catch (HostNetworkError error) {
show_error(this, error.what());
}
}

View File

@ -62,11 +62,14 @@ bool Repetier::test(wxString &msg) const
std::stringstream ss(body);
pt::ptree ptree;
pt::read_json(ss, ptree);
const auto text = ptree.get_optional<std::string>("name");
res = validate_version_text(text);
if (! res) {
msg = GUI::from_u8((boost::format(_u8L("Mismatched type of print host: %s")) % (text ? *text : "Repetier")).str());
res = ptree.get_optional<std::string>("name").has_value();
if (!res)
msg = GUI::from_u8((boost::format(_u8L("Can't process the repetier return message: missing field '%s'")) % ("name")).str());
else {
res = ptree.get_optional<std::string>("printers").has_value();
if (!res)
msg = GUI::from_u8((boost::format(_u8L("Can't process the repetier return message: missing field '%s'")) % ("printers")).str());
}
}
catch (const std::exception &) {