diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index bb93e83ec9..18f8cadb6a 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -964,8 +964,8 @@ void GUI_App::post_init() std::string network_ver = Slic3r::NetworkAgent::get_version(); bool sys_preset = app_config->get("sync_system_preset") == "true"; this->preset_updater->sync(http_url, language, network_ver, sys_preset ? preset_bundle : nullptr); - - this->check_new_version_sf(); + this->preset_updater->sync_web_async(true); + this->check_new_version_sf(false, false); }); } @@ -4754,14 +4754,15 @@ void GUI_App::check_new_version_sf(bool show_tips, bool by_user) AppConfig* app_config = wxGetApp().app_config; Http::get(update_url) - .on_error([&](std::string body, std::string error, unsigned http_status) { + .on_error([&, by_user](std::string body, std::string error, unsigned http_status) { (void)body; wxCommandEvent* evt = new wxCommandEvent(EVT_REQUEST_SERVER_FAIL); wxString errorMsg = wxString::Format(_L("request to server update soft fail with body:%s,error:%s,status:%d"), body, error, http_status); evt->SetString(errorMsg); - GUI::wxGetApp().QueueEvent(evt); + if(by_user) + GUI::wxGetApp().QueueEvent(evt); BOOST_LOG_TRIVIAL(error) << format("Error getting: `%1%`: HTTP %2%, %3%", "check_new_version_sf", http_status, error); }) @@ -4778,10 +4779,10 @@ void GUI_App::check_new_version_sf(bool show_tips, bool by_user) if (errCode != 200) return; - auto dataObj = jsonObj.value("data", json::object()); - + auto dataObj = jsonObj.value("data", json::object()); auto isFullUpgrade = dataObj.value("is_full_upgrade", true); auto isForceUpgrade = dataObj.value("is_force_upgrade", false); + version_info.force_upgrade = isForceUpgrade; version_info.version_str = dataObj.value("version", ""); auto releaseType = dataObj.value("release_type", ""); @@ -4792,17 +4793,61 @@ void GUI_App::check_new_version_sf(bool show_tips, bool by_user) std::string reservedData = ""; std::string reservedData2 = ""; + // win x86_x64, mac arm/x86_x64 universal auto fullObj = dataObj.value("full", json::object()); - fileSize = fullObj.value("file_size", 0); - fileMd5 = fullObj.value("file_md5", ""); - fileSha256 = fullObj.value("file_sha256", ""); - // windows x86_x64, mac arm/x86_x64 universal - version_info.url = fullObj.value("file_url", ""); + auto defaultObj = fullObj.value("default", json::object()); + auto armObj = fullObj.value("arm", json::object()); + auto intelObj = fullObj.value("intel", json::object()); version_info.description = fullObj.value("file_describe", ""); - reservedData = fullObj.value("reserved_1", ""); - reservedData2 = fullObj.value("reserved_2", ""); - version_info.force_upgrade = isForceUpgrade; + if (platformType == "win") { + fileSize = defaultObj.value("file_size", 0); + fileMd5 = defaultObj.value("file_md5", ""); + fileSha256 = defaultObj.value("file_sha256", ""); + version_info.url = defaultObj.value("file_url", ""); + + reservedData = defaultObj.value("reserved_1", ""); + reservedData2 = defaultObj.value("reserved_2", ""); + } + else if (platformType == "mac") + { + + if (platformType == "arm") + { + fileSize = armObj.value("file_size", 0); + fileMd5 = armObj.value("file_md5", ""); + fileSha256 = armObj.value("file_sha256", ""); + version_info.url = armObj.value("file_url", ""); + + reservedData = armObj.value("reserved_1", ""); + reservedData2 = armObj.value("reserved_2", ""); + } + else if (platformType == "intel") + { + fileSize = intelObj.value("file_size", 0); + fileMd5 = intelObj.value("file_md5", ""); + fileSha256 = intelObj.value("file_sha256", ""); + version_info.url = intelObj.value("file_url", ""); + + reservedData = intelObj.value("reserved_1", ""); + reservedData2 = intelObj.value("reserved_2", ""); + } + + if (intelObj.empty() && armObj.empty()) { + fileSize = defaultObj.value("file_size", 0); + fileMd5 = defaultObj.value("file_md5", ""); + fileSha256 = defaultObj.value("file_sha256", ""); + version_info.url = defaultObj.value("file_url", ""); + + reservedData = defaultObj.value("reserved_1", ""); + reservedData2 = defaultObj.value("reserved_2", ""); + } + } + else + { + BOOST_LOG_TRIVIAL(warning) << "don't support linux upgrade"; + return; + } std::regex matcher("[0-9]+\\.[0-9]+(\\.[0-9]+)*(-[A-Za-z0-9]+)?(\\+[A-Za-z0-9]+)?"); Semver current_version = get_version(Snapmaker_VERSION, matcher); diff --git a/src/slic3r/GUI/UpdateDialogs.cpp b/src/slic3r/GUI/UpdateDialogs.cpp index 9a9f2eafd1..6f7c88151f 100644 --- a/src/slic3r/GUI/UpdateDialogs.cpp +++ b/src/slic3r/GUI/UpdateDialogs.cpp @@ -176,17 +176,12 @@ MsgUpdateConfig::MsgUpdateConfig(const std::vector &updates, bool force_ wxBoxSizer *content_sizer = new wxBoxSizer(wxVERTICAL); - - - - const auto lang_code = wxGetApp().current_language_code_safe().ToStdString(); auto *versions = new wxBoxSizer(wxVERTICAL); // BBS: use changelog string instead of url wxStaticText *changelog_textctrl = new wxStaticText(m_scrollwindw_release_note, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(FromDIP(560), -1)); - for (const auto &update : updates) { auto* versions = new wxBoxSizer(wxVERTICAL); wxStaticText* changelog_textctrl = new wxStaticText(m_scrollwindw_release_note, wxID_ANY, wxEmptyString, wxDefaultPosition, @@ -211,12 +206,8 @@ MsgUpdateConfig::MsgUpdateConfig(const std::vector &updates, bool force_ versions->Add(flex); - - - // BBS: use changelog string instead of url - - //auto change_log = new wxStaticText(m_scrollwindw_release_note, wxID_ANY, from_u8(update.change_log), wxDefaultPosition, wxDefaultSize); - changelog_textctrl->SetLabel(changelog_textctrl->GetLabel() + wxString::Format("%s\n", from_u8(update.change_log))); + //auto change_log = new wxStaticText(m_scrollwindw_release_note, wxID_ANY, from_u8(update.change_log), wxDefaultPosition, wxDefaultSize); + changelog_textctrl->SetLabel(changelog_textctrl->GetLabel() + wxString::Format("%s\n", from_u8(update.change_log))); content_sizer->Add(versions); @@ -224,16 +215,13 @@ MsgUpdateConfig::MsgUpdateConfig(const std::vector &updates, bool force_ if (changelog_textctrl) content_sizer->Add(changelog_textctrl, 1, wxEXPAND | wxTOP, FromDIP(30)); } - m_butto_ok->Bind(wxEVT_BUTTON, [this](const wxCommandEvent &) { EndModal(wxID_OK); }); m_button_cancel->Bind(wxEVT_BUTTON, [this](const wxCommandEvent &) { EndModal(wxID_CLOSE); }); - m_scrollwindw_release_note->SetSizer(content_sizer); m_scrollwindw_release_note->Layout(); - SetSizer(m_sizer_main); Layout(); m_sizer_main->Fit(this); diff --git a/src/slic3r/Utils/PresetUpdater.cpp b/src/slic3r/Utils/PresetUpdater.cpp index 3906ccbf74..4604c1a51b 100644 --- a/src/slic3r/Utils/PresetUpdater.cpp +++ b/src/slic3r/Utils/PresetUpdater.cpp @@ -726,7 +726,8 @@ void PresetUpdater::priv::sync_update_flutter_resource(bool isAuto_check) wxCommandEvent* evt = new wxCommandEvent(EVT_REQUEST_SERVER_FAIL); wxString errorMsg = wxString::Format(_L("request to server update web resource fail with body:%s,error:%s,status:%d"), body, error, http_status); evt->SetString(errorMsg); - GUI::wxGetApp().QueueEvent(evt); + if (!isAuto_check) + GUI::wxGetApp().QueueEvent(evt); BOOST_LOG_TRIVIAL(info) << format("Error getting: `%1%`: HTTP %2%, %3%", "sync_update_flutter_resource", http_status, error); }) .timeout_connect(TIMEOUT_CONNECT) @@ -760,6 +761,24 @@ void PresetUpdater::priv::sync_update_flutter_resource(bool isAuto_check) std::string fileName = cache_profile_path.string() + "/flutter_web.zip"; Semver currentPresetVersion = get_version_from_json(json_path); Semver remoteVersion(fileVersion); + Semver minSpVersion(minSupportPcVersion); + Semver maxSpVersion(maxSupportPcVersion); + std::regex matcher("[0-9]+\\.[0-9]+(\\.[0-9]+)*(-[A-Za-z0-9]+)?(\\+[A-Za-z0-9]+)?"); + + auto get_version = [this](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(); + }; + + Semver currentSoftVersion = get_version(Snapmaker_VERSION, matcher); if (fileVersion.empty()) { @@ -772,24 +791,14 @@ void PresetUpdater::priv::sync_update_flutter_resource(bool isAuto_check) return; } - std::string localOtaPresetVersion = ""; - if (fs::exists(localProfilesjson)) { - Semver localOtaVersion = get_version_from_json(localProfilesjson.string()); + if (currentSoftVersion > maxSpVersion || currentSoftVersion < minSpVersion) { + if (!isAuto_check) { + wxCommandEvent* evt = new wxCommandEvent(EVT_NO_PRESET_UPDATE); + GUI::wxGetApp().QueueEvent(evt); - if (localOtaVersion > remoteVersion) - return; - else { - if (currentPresetVersion >= remoteVersion){ - if (!isAuto_check) { - wxCommandEvent* evt = new wxCommandEvent(EVT_NO_WEB_RESOURCE_UPDATE); - GUI::wxGetApp().QueueEvent(evt); - - BOOST_LOG_TRIVIAL(info) << format("use check the web update."); - } - return; - } - + BOOST_LOG_TRIVIAL(info) << format("use check the web update."); } + return; } if (currentPresetVersion < remoteVersion) @@ -824,7 +833,8 @@ void PresetUpdater::priv::sync_config(bool isAuto_check) wxCommandEvent* evt = new wxCommandEvent(EVT_REQUEST_SERVER_FAIL); wxString errorMsg = wxString::Format(_L("request to server update preset resource fail with body:%s,error:%s,status:%d"), body,error, http_status); evt->SetString(errorMsg); - GUI::wxGetApp().QueueEvent(evt); + if (!isAuto_check) + GUI::wxGetApp().QueueEvent(evt); BOOST_LOG_TRIVIAL(info) << format("Error getting: `%1%`: HTTP %2%, %3%", "sync_config_orca", http_status, error); }) .timeout_connect(TIMEOUT_CONNECT) @@ -857,6 +867,24 @@ void PresetUpdater::priv::sync_config(bool isAuto_check) std::string fileName = cache_profile_path.string() + "/profiles.zip"; Semver currentPresetVersion = get_version_from_json(json_path); Semver remoteVersion(fileVersion); + Semver minSpVersion(minSupportPcVersion); + Semver maxSpVersion(maxSupportPcVersion); + + std::regex matcher("[0-9]+\\.[0-9]+(\\.[0-9]+)*(-[A-Za-z0-9]+)?(\\+[A-Za-z0-9]+)?"); + + auto get_version = [this](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(); + }; + + Semver currentSoftVersion = get_version(Snapmaker_VERSION, matcher); if (fileVersion.empty()) { if (!isAuto_check) { @@ -868,23 +896,15 @@ void PresetUpdater::priv::sync_config(bool isAuto_check) return; } - std::string localOtaPresetVersion = ""; - if (fs::exists(localProfilesjson)) { - Semver localOtaVersion = get_version_from_json(localProfilesjson.string()); - //don't allow jump version. first upgrade localOta - if (localOtaVersion > currentPresetVersion) - return; - else - { - if (currentPresetVersion >= remoteVersion) { - if (!isAuto_check) {//show tipsdlg by user check upgrade - wxCommandEvent* evt = new wxCommandEvent(EVT_NO_PRESET_UPDATE); - GUI::wxGetApp().QueueEvent(evt); - BOOST_LOG_TRIVIAL(info) << format("use check the preset update."); - } - return; - } - } + if (currentSoftVersion > maxSpVersion || currentSoftVersion < minSpVersion) + { + if (!isAuto_check) { + wxCommandEvent* evt = new wxCommandEvent(EVT_NO_PRESET_UPDATE); + GUI::wxGetApp().QueueEvent(evt); + + BOOST_LOG_TRIVIAL(info) << format("use check the web update."); + } + return; } if (currentPresetVersion < remoteVersion) @@ -1675,7 +1695,7 @@ bool PresetUpdater::install_bundles_rsrc(std::vector bundles, bool return p->install_bundles_rsrc(bundles, snapshot); } -void PresetUpdater::sync_web_async() +void PresetUpdater::sync_web_async(bool isAutoUpdata) { if (p->thread.joinable()) { p->cancel = true; @@ -1683,9 +1703,9 @@ void PresetUpdater::sync_web_async() } p->cancel = false; - p->thread = std::thread([this]() { + p->thread = std::thread([this, isAutoUpdata]() { BOOST_LOG_TRIVIAL(debug) << "[Orca Updater] sync_web_async started"; - this->p->sync_update_flutter_resource(false); + this->p->sync_update_flutter_resource(isAutoUpdata); GUI::wxGetApp().CallAfter([this] { std::string zipfilepath = this->p->cache_path.string() + "/flutter_web.zip"; @@ -1783,7 +1803,8 @@ void PresetUpdater::load_lutter_web(const std::string& zip_file, bool serverUpda boost::filesystem::create_directories(temp_path); if (!p->extract_file(zip_file, temp_path.string())) { - GUI::MessageDialog(nullptr, _L("Import Failed")).ShowModal(); + if (!serverUpdate) + GUI::MessageDialog(nullptr, _L("Import Failed")).ShowModal(); return; } diff --git a/src/slic3r/Utils/PresetUpdater.hpp b/src/slic3r/Utils/PresetUpdater.hpp index b18857245a..f309654c5d 100644 --- a/src/slic3r/Utils/PresetUpdater.hpp +++ b/src/slic3r/Utils/PresetUpdater.hpp @@ -69,7 +69,7 @@ public: void sync_config_async(); - void sync_web_async(); + void sync_web_async(bool isAutoUpdata = false); public: struct priv; std::unique_ptr p;