Skip to content

Commit

Permalink
Repetier validation using 'software' value if present prusa3d#7807
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasmatena committed Sep 5, 2022
1 parent 4e315bc commit 39af553
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
30 changes: 23 additions & 7 deletions src/slic3r/Utils/Repetier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,24 @@ Repetier::Repetier(DynamicPrintConfig *config) :

const char* Repetier::get_name() const { return "Repetier"; }



static bool validate_repetier(const boost::optional<std::string>& name,
const boost::optional<std::string>& soft)
{
if (soft) {
// See https://github.com/prusa3d/PrusaSlicer/issues/7807:
// Repetier allows "rebranding", so the "name" value is not reliable when detecting
// server type. Newer Repetier versions send "software", which should be invariant.
return ((*soft) == "Repetier-Server");
} else {
// If there is no "software" value, validate as we did before:
return name ? boost::starts_with(*name, "Repetier") : true;
}
}



bool Repetier::test(wxString &msg) const
{
// Since the request is performed synchronously here,
Expand Down Expand Up @@ -62,11 +80,12 @@ 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);
const auto soft = ptree.get_optional<std::string>("software");
res = validate_repetier(text, soft);
if (! res) {
msg = GUI::from_u8((boost::format(_utf8(L("Mismatched type of print host: %s"))) % (text ? *text : "Repetier")).str());
msg = GUI::from_u8((boost::format(_utf8(L("Mismatched type of print host: %s"))) % (soft ? *soft : (text ? *text : "Repetier"))).str());
}
}
catch (const std::exception &) {
Expand Down Expand Up @@ -154,10 +173,7 @@ bool Repetier::upload(PrintHostUpload upload_data, ProgressFn prorgess_fn, Error
return res;
}

bool Repetier::validate_version_text(const boost::optional<std::string> &version_text) const
{
return version_text ? boost::starts_with(*version_text, "Repetier") : true;
}


void Repetier::set_auth(Http &http) const
{
Expand Down
3 changes: 0 additions & 3 deletions src/slic3r/Utils/Repetier.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ class Repetier : public PrintHost
bool get_groups(wxArrayString &groups) const override;
bool get_printers(wxArrayString &printers) const override;

protected:
virtual bool validate_version_text(const boost::optional<std::string> &version_text) const;

private:
std::string host;
std::string apikey;
Expand Down

0 comments on commit 39af553

Please sign in to comment.