From 020423542d6dbd194a0f0d8182e1968c4831de06 Mon Sep 17 00:00:00 2001 From: alves Date: Mon, 5 Jan 2026 17:36:27 +0800 Subject: [PATCH] feature diff cn and the other area to download soft.and request to server fail show the error dialog. --- src/libslic3r/AppConfig.cpp | 25 +++++++++++++++++++++++++ src/libslic3r/AppConfig.hpp | 1 + src/slic3r/GUI/GUI_App.cpp | 26 ++++++++++++++------------ src/slic3r/GUI/Preferences.cpp | 8 ++++---- src/slic3r/Utils/PresetUpdater.cpp | 18 ++++++++++++++---- src/slic3r/Utils/PresetUpdater.hpp | 1 + 6 files changed, 59 insertions(+), 20 deletions(-) diff --git a/src/libslic3r/AppConfig.cpp b/src/libslic3r/AppConfig.cpp index cf8800fda1..d7fbed9d27 100644 --- a/src/libslic3r/AppConfig.cpp +++ b/src/libslic3r/AppConfig.cpp @@ -43,6 +43,20 @@ static const std::string PROFILE_UPDATE_URL = "https://public.resource.snapmaker static const std::string FLUTTER_UPDATE_URL = "https://public.resource.snapmaker.com/upgrade/packages/flutter/flutter_config.json"; static const std::string MODELS_STR = "models"; +#define APP_UPDATE_URL_BASE_CN "https://public.resource.snapmaker.com/upgrade/packages/orca" +#define APP_UPDATE_URL_BASE_EN "https://public.resource.snapmaker.com/upgrade/packages/orca" + +#if defined(_WIN32) +static const std::string APP_UPDATE_URL = std::string("/win/manifest.json"); +#elif defined(__APPLE__) +static const std::string APP_UPDATE_URL = std::string("/mac/manifest.json"); +#elif defined(__linux__) +static const std::string APP_UPDATE_URL = std::string("/linux/manifest.json"); +#else +static const std::string APP_UPDATE_URL = ""; +#endif + + const std::string AppConfig::SECTION_FILAMENTS = "filaments"; const std::string AppConfig::SECTION_MATERIALS = "sla_materials"; const std::string AppConfig::SECTION_EMBOSS_STYLE = "font"; @@ -1424,6 +1438,17 @@ std::string AppConfig::config_path() return path; } +std::string AppConfig::get_version_upgrade_url(bool stable_only /* = false*/) +{ + //get local area and get the resource from diff server + std::string url = APP_UPDATE_URL_BASE_EN + APP_UPDATE_URL; + auto countryArea = get_country_code(); + if (countryArea == std::string("CN")) + url = APP_UPDATE_URL_BASE_CN + APP_UPDATE_URL; + + return url; +} + std::string AppConfig::version_check_url(bool stable_only/* = false*/) const { auto from_settings = get("version_check_url"); diff --git a/src/libslic3r/AppConfig.hpp b/src/libslic3r/AppConfig.hpp index d70bb36af8..04770946d5 100644 --- a/src/libslic3r/AppConfig.hpp +++ b/src/libslic3r/AppConfig.hpp @@ -324,6 +324,7 @@ public: // Get the Slic3r version check url. // This returns a hardcoded string unless it is overriden by "version_check_url" in the ini file. std::string version_check_url(bool stable_only = false) const; + std::string get_version_upgrade_url(bool stable_only = false); // Get the Orca profile update url. std::string profile_update_url() const; diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index 366c5410f1..2032eca133 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -2592,6 +2592,12 @@ bool GUI_App::on_init_inner() InfoDialog dlg(nullptr, _L("Info"), msg); dlg.ShowModal(); }); + + Bind(EVT_REQUEST_SERVER_FAIL, [this](const wxCommandEvent& evt) { + wxString msg = evt.GetString(); + InfoDialog dlg(nullptr, _L("Error"), msg); + dlg.ShowModal(); + }); } else { #ifdef __WXMSW__ @@ -4751,27 +4757,23 @@ void GUI_App::check_preset_version() } void GUI_App::check_new_version_sf(bool show_tips, bool by_user) { - std::string update_url = ""; - -#ifdef __WINDOWS__ - update_url = "https://public.resource.snapmaker.com/upgrade/packages/orca/win/manifest.json"; -#endif -#ifdef __APPLE__ - update_url = "https://public.resource.snapmaker.com/upgrade/packages/orca/mac/manifest.json"; -#endif -#ifdef __LINUX__ - update_url = "https://public.resource.snapmaker.com/upgrade/packages/orca/linux/manifest.json"; -#endif + std::string update_url = app_config->get_version_upgrade_url(); AppConfig* app_config = wxGetApp().app_config; Http::get(update_url) .on_error([&](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); BOOST_LOG_TRIVIAL(error) << format("Error getting: `%1%`: HTTP %2%, %3%", "check_new_version_sf", http_status, error); }) - .timeout_connect(1) + .timeout_connect(TIMEOUT_CONNECT) .on_complete([this,by_user](std::string body, unsigned http_status) { // Http response OK if (http_status != 200) { diff --git a/src/slic3r/GUI/Preferences.cpp b/src/slic3r/GUI/Preferences.cpp index d7d5240070..e01861b8a1 100644 --- a/src/slic3r/GUI/Preferences.cpp +++ b/src/slic3r/GUI/Preferences.cpp @@ -1196,7 +1196,7 @@ wxWindow* PreferencesDialog::create_general_page() app_config->save(); - auto item_check_stable_version_only = create_item_checkbox(_L("Check for stable updates only"), page, _L("Check for stable updates only"), 50, "check_stable_update_only"); + //auto item_check_stable_version_only = create_item_checkbox(_L("Check for stable updates only"), page, _L("Check for stable updates only"), 50, "check_stable_update_only"); std::vector Units = {_L("Metric") + " (mm, g)", _L("Imperial") + " (in, oz)"}; auto item_currency = create_item_combobox(_L("Units"), page, _L("Units"), "use_inches", Units); @@ -1231,7 +1231,7 @@ wxWindow* PreferencesDialog::create_general_page() auto item_multi_machine = create_item_checkbox(_L("Multi-device Management (Take effect after restarting Snapmaker Orca)."), page, _L("With this option enabled, you can send a task to multiple devices at the same time and manage multiple devices."), 50, "enable_multi_machine"); auto item_auto_arrange = create_item_checkbox(_L("Auto arrange plate after cloning"), page, _L("Auto arrange plate after object cloning"), 50, "auto_arrange"); auto title_presets = create_item_title(_L("Presets"), page, _L("Presets")); - auto title_network = create_item_title(_L("Network"), page, _L("Network")); + //auto title_network = create_item_title(_L("Network"), page, _L("Network")); auto item_user_sync = create_item_checkbox(_L("Auto sync user presets (Printer/Filament/Process)"), page, _L("User Sync"), 50, "sync_user_preset"); auto item_system_sync = create_item_checkbox(_L("Update built-in Presets automatically."), page, _L("System Sync"), 50, "sync_system_preset"); auto item_save_presets = create_item_button(_L("Clear my choice on the unsaved presets."), _L("Clear"), page, L"", _L("Clear my choice on the unsaved presets."), []() { @@ -1336,8 +1336,8 @@ wxWindow* PreferencesDialog::create_general_page() sizer_page->Add(item_system_sync, 0, wxTOP, FromDIP(3)); sizer_page->Add(item_remember_printer_config, 0, wxTOP, FromDIP(3)); sizer_page->Add(item_save_presets, 0, wxTOP, FromDIP(3)); - sizer_page->Add(title_network, 0, wxTOP | wxEXPAND, FromDIP(20)); - sizer_page->Add(item_check_stable_version_only, 0, wxTOP, FromDIP(3)); + //sizer_page->Add(title_network, 0, wxTOP | wxEXPAND, FromDIP(20)); + //sizer_page->Add(item_check_stable_version_only, 0, wxTOP, FromDIP(3)); // SM Beta: temporarily open the item_stealth_mode and close the network plugin diff --git a/src/slic3r/Utils/PresetUpdater.cpp b/src/slic3r/Utils/PresetUpdater.cpp index fab0e940d7..31208f5f53 100644 --- a/src/slic3r/Utils/PresetUpdater.cpp +++ b/src/slic3r/Utils/PresetUpdater.cpp @@ -181,6 +181,7 @@ struct Updates std::vector updates; }; +wxDEFINE_EVENT(EVT_REQUEST_SERVER_FAIL, wxCommandEvent); wxDEFINE_EVENT(EVT_NO_WEB_RESOURCE_UPDATE, wxCommandEvent); wxDEFINE_EVENT(EVT_NO_PRESET_UPDATE, wxCommandEvent); wxDEFINE_EVENT(EVT_SLIC3R_VERSION_ONLINE, wxCommandEvent); @@ -722,9 +723,14 @@ void PresetUpdater::priv::sync_update_flutter_resource(bool isAuto_check) Http::get(preset_update_url) .on_error([cache_profile_path, isAuto_check](std::string body, std::string error, unsigned http_status) { + 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); + GUI::wxGetApp().QueueEvent(evt); BOOST_LOG_TRIVIAL(info) << format("Error getting: `%1%`: HTTP %2%, %3%", "sync_update_flutter_resource", http_status, error); }) - .timeout_connect(5) + .timeout_connect(TIMEOUT_CONNECT) .on_complete([this, cache_profile_path, isAuto_check](std::string body, unsigned http_status) { // Http response OK if (http_status != 200) @@ -756,7 +762,7 @@ void PresetUpdater::priv::sync_update_flutter_resource(bool isAuto_check) if (fs::exists(localProfilesjson)) { Semver localOtaVersion = get_version_from_json(localProfilesjson.string()); - if (localOtaVersion >= remoteVersion) + if (localOtaVersion > remoteVersion) return; else { if (currentPresetVersion >= remoteVersion){ @@ -802,9 +808,13 @@ void PresetUpdater::priv::sync_config(bool isAuto_check) .on_error([cache_profile_path, isAuto_check](std::string body, std::string error, unsigned http_status) { // Orca: we check the response body to see if it's "Not Found", if so, it means for the current Orca version we don't have OTA // updates, we can delete the cache file + 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); BOOST_LOG_TRIVIAL(info) << format("Error getting: `%1%`: HTTP %2%, %3%", "sync_config_orca", http_status, error); }) - .timeout_connect(5) + .timeout_connect(TIMEOUT_CONNECT) .on_complete([this, cache_profile_path, isAuto_check](std::string body, unsigned http_status) { // Http response OK if (http_status != 200) @@ -835,7 +845,7 @@ void PresetUpdater::priv::sync_config(bool isAuto_check) if (fs::exists(localProfilesjson)) { Semver localOtaVersion = get_version_from_json(localProfilesjson.string()); //don't allow jump version. first upgrade localOta - if (localOtaVersion >= currentPresetVersion) + if (localOtaVersion > currentPresetVersion) return; else { diff --git a/src/slic3r/Utils/PresetUpdater.hpp b/src/slic3r/Utils/PresetUpdater.hpp index c1c7a49638..b18857245a 100644 --- a/src/slic3r/Utils/PresetUpdater.hpp +++ b/src/slic3r/Utils/PresetUpdater.hpp @@ -74,6 +74,7 @@ public: struct priv; std::unique_ptr p; }; +wxDECLARE_EVENT(EVT_REQUEST_SERVER_FAIL, wxCommandEvent); wxDECLARE_EVENT(EVT_NO_WEB_RESOURCE_UPDATE, wxCommandEvent); wxDECLARE_EVENT(EVT_NO_PRESET_UPDATE, wxCommandEvent); wxDECLARE_EVENT(EVT_SLIC3R_VERSION_ONLINE, wxCommandEvent);