diff --git a/src/libslic3r/AppConfig.cpp b/src/libslic3r/AppConfig.cpp index 0fd431972c..87b3c236a0 100644 --- a/src/libslic3r/AppConfig.cpp +++ b/src/libslic3r/AppConfig.cpp @@ -38,7 +38,7 @@ using namespace nlohmann; namespace Slic3r { -static const std::string VERSION_CHECK_URL = ""; +static const std::string VERSION_CHECK_URL = "https://api.github.com/repos/softfever/bambustudio-softfever/releases"; static const std::string MODELS_STR = "models"; const std::string AppConfig::SECTION_FILAMENTS = "filaments"; diff --git a/src/libslic3r/Semver.hpp b/src/libslic3r/Semver.hpp index aa0947aa35..cdc96f108b 100644 --- a/src/libslic3r/Semver.hpp +++ b/src/libslic3r/Semver.hpp @@ -141,6 +141,15 @@ public: if (ver.metadata != nullptr) { res += '+'; res += ver.metadata; } return res; } + std::string to_string_sf() const { + //BBS: version format + std::string res; + res = (boost::format("%1%.%2%.%3%") % ver.major % ver.minor % ver.patch).str(); + + if (ver.prerelease != nullptr) { res += '-'; res += ver.prerelease; } + if (ver.metadata != nullptr) { res += '+'; res += ver.metadata; } + return res; + } // Arithmetics Semver& operator+=(const Major &b) { ver.major += b.i; return *this; } diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index e23e5b0d90..8104e8cf60 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -1118,7 +1118,7 @@ void GUI_App::post_init() this->preset_updater->sync(http_url, language, network_ver, preset_bundle); //BBS: check new version - //this->check_new_version(); + this->check_new_version_sf(); }); } @@ -3805,6 +3805,101 @@ void GUI_App::check_new_version(bool show_tips, int by_user) }).perform(); } +//parse the string, if it doesn't contain a valid version string, return invalid version. +Semver get_version(const std::string& str, const std::regex& regexp) { + std::smatch match; + if (std::regex_match(str, match, regexp)) { + std::string version_cleaned = match[0]; + const boost::optional version = Semver::parse(version_cleaned); + if (version.has_value()) { + return *version; + } + } + return Semver::invalid(); +} + +void GUI_App::check_new_version_sf(bool show_tips, int by_user) +{ + AppConfig* app_config = wxGetApp().app_config; + auto version_check_url = app_config->version_check_url(); + Http::get(version_check_url).on_error([&](std::string body, std::string error, unsigned http_status) { + (void)body; + BOOST_LOG_TRIVIAL(error) << format("Error getting: `%1%`: HTTP %2%, %3%", + version_check_url, + http_status, + error); + }) + .timeout_connect(1) + .on_complete([&](std::string body, unsigned /* http_status */) { + boost::trim(body); + // SoftFever: parse github release, ported from SS + + boost::property_tree::ptree root; + std::stringstream json_stream(body); + boost::property_tree::read_json(json_stream, root); + bool i_am_pre = false; + //at least two number, use '.' as separator. can be followed by -Az23 for prereleased and +Az42 for metadata + std::regex matcher("[0-9]+\\.[0-9]+(\\.[0-9]+)*(-[A-Za-z0-9]+)?(\\+[A-Za-z0-9]+)?"); + + Semver current_version = get_version(SoftFever_VERSION, matcher); + Semver best_pre(1, 0, 0); + Semver best_release(1, 0, 0); + std::string best_pre_url; + std::string best_release_url; + std::string best_release_content; + std::string best_pre_content; + const std::regex reg_num("([0-9]+)"); + for (auto json_version : root) { + std::string tag = json_version.second.get("tag_name"); + if (tag[0] == 'v') + tag.erase(0, 1); + for (std::regex_iterator it = std::sregex_iterator(tag.begin(), tag.end(), reg_num); it != std::sregex_iterator(); ++it) { + + } + Semver tag_version = get_version(tag, matcher); + if (current_version == tag_version) + i_am_pre = json_version.second.get("prerelease"); + if (json_version.second.get("prerelease")) { + if (best_pre < tag_version) { + best_pre = tag_version; + best_pre_url = json_version.second.get("html_url"); + best_pre_content = json_version.second.get("body"); + best_pre.set_prerelease("Preview"); + } + } + else { + if (best_release < tag_version) { + best_release = tag_version; + best_release_url = json_version.second.get("html_url"); + best_release_content = json_version.second.get("body"); + } + } + } + + //if release is more recent than beta, use release anyway + if (best_pre < best_release) { + best_pre = best_release; + best_pre_url = best_release_url; + best_pre_content = best_release_content; + } + //if we're the most recent, don't do anything + if ((i_am_pre ? best_pre : best_release) <= current_version) + return; + + //BOOST_LOG_TRIVIAL(info) << format("Got %1% online version: `%2%`. Sending to GUI thread...", SLIC3R_APP_NAME, i_am_pre ? best_pre.to_string(): best_release.to_string()); + + version_info.url = i_am_pre ? best_pre_url : best_release_url; + version_info.version_str = i_am_pre ? best_pre.to_string() : best_release.to_string_sf(); + version_info.description = i_am_pre ? best_pre_content : best_release_content; + version_info.force_upgrade = false; + + wxCommandEvent* evt = new wxCommandEvent(EVT_SLIC3R_VERSION_ONLINE); + evt->SetString((i_am_pre ? best_pre : best_release).to_string()); + GUI::wxGetApp().QueueEvent(evt); + }) + .perform_sync();; + +} //BBS pop up a dialog and download files void GUI_App::request_new_version(int by_user) diff --git a/src/slic3r/GUI/GUI_App.hpp b/src/slic3r/GUI/GUI_App.hpp index c0fac3700d..1345843f63 100644 --- a/src/slic3r/GUI/GUI_App.hpp +++ b/src/slic3r/GUI/GUI_App.hpp @@ -410,6 +410,7 @@ public: void check_update(bool show_tips, int by_user); void check_new_version(bool show_tips = false, int by_user = 0); + void check_new_version_sf(bool show_tips = false, int by_user = 0); void request_new_version(int by_user); void enter_force_upgrade(); void set_skip_version(bool skip = true); diff --git a/src/slic3r/GUI/MainFrame.cpp b/src/slic3r/GUI/MainFrame.cpp index f5fe4941b9..e78d715416 100644 --- a/src/slic3r/GUI/MainFrame.cpp +++ b/src/slic3r/GUI/MainFrame.cpp @@ -1915,7 +1915,7 @@ static wxMenu* generate_help_menu() // Check New Version append_menu_item(helpMenu, wxID_ANY, _L("Check for Update"), _L("Check for Update"), [](wxCommandEvent&) { - wxGetApp().check_new_version(true, 1); + wxGetApp().check_new_version_sf(true, 1); }, "", nullptr, []() { return true; }); diff --git a/src/slic3r/GUI/ReleaseNote.cpp b/src/slic3r/GUI/ReleaseNote.cpp index fca89f4f28..01d9b2917f 100644 --- a/src/slic3r/GUI/ReleaseNote.cpp +++ b/src/slic3r/GUI/ReleaseNote.cpp @@ -316,7 +316,7 @@ void UpdateVersionDialog::update_version_info(wxString release_note, wxString ve //bbs check whether the web display is used bool use_web_link = false; std::string url_line = ""; - auto split_array = splitWithStl(release_note.ToStdString(), "###"); + /*auto split_array = splitWithStl(release_note.ToStdString(), "\r\n"); for (auto i = 0; i < split_array.size(); i++) { std::string url = split_array[i]; @@ -331,7 +331,7 @@ void UpdateVersionDialog::update_version_info(wxString release_note, wxString ve m_simplebook_release_note->SetSelection(1); m_vebview_release_note->LoadURL(from_u8(url_line)); } - else { + else {*/ m_simplebook_release_note->SetSelection(0); m_text_up_info->SetLabel(wxString::Format(_L("Click to download new version in default browser: %s"), version)); wxBoxSizer* sizer_text_release_note = new wxBoxSizer(wxVERTICAL); @@ -341,7 +341,7 @@ void UpdateVersionDialog::update_version_info(wxString release_note, wxString ve m_scrollwindows_release_note->SetSizer(sizer_text_release_note); m_scrollwindows_release_note->Layout(); m_scrollwindows_release_note->Fit(); - } + //} } SecondaryCheckDialog::SecondaryCheckDialog(wxWindow* parent, wxWindowID id, const wxString& title, enum ButtonStyle btn_style, const wxPoint& pos, const wxSize& size, long style, bool not_show_again_check)