From 0e5a816318d019734c5c808b4a5762c1a999dfa0 Mon Sep 17 00:00:00 2001 From: SoftFever Date: Sun, 28 Dec 2025 19:57:08 +0800 Subject: [PATCH] Migrate legacy networking configuration to new network plugin versioning system. Remove legacy networking setting and update related GUI components to reflect the changes. Implement auto-migration for legacy libraries to ensure compatibility with the new versioning scheme. --- src/libslic3r/AppConfig.cpp | 22 ++++++++-- src/libslic3r/AppConfig.hpp | 1 + src/slic3r/GUI/GUI_App.cpp | 14 +++--- src/slic3r/GUI/Preferences.cpp | 34 ++++++--------- src/slic3r/GUI/Preferences.hpp | 1 - src/slic3r/Utils/NetworkAgent.cpp | 62 ++++++++++++++++++++++----- src/slic3r/Utils/bambu_networking.hpp | 3 +- 7 files changed, 93 insertions(+), 44 deletions(-) diff --git a/src/libslic3r/AppConfig.cpp b/src/libslic3r/AppConfig.cpp index ad0a8e5932..4d91275010 100644 --- a/src/libslic3r/AppConfig.cpp +++ b/src/libslic3r/AppConfig.cpp @@ -135,6 +135,25 @@ void AppConfig::set_defaults() if (!get("use_legacy_opengl").empty()) erase("app", "use_legacy_opengl"); + // Migrate legacy_networking boolean to network_plugin_version string + std::string legacy_networking = get("legacy_networking"); + std::string network_version = get("network_plugin_version"); + + if (!legacy_networking.empty()) { + // Old legacy_networking setting exists - migrate it + bool was_legacy = (legacy_networking == "true" || legacy_networking == "1"); + + if (was_legacy && network_version.empty()) { + // User had legacy mode enabled - set to legacy version number + BOOST_LOG_TRIVIAL(info) << "Migrating legacy_networking=true to network_plugin_version=01.10.01.01"; + set("network_plugin_version", BAMBU_NETWORK_AGENT_VERSION_LEGACY); + } + // Note: If was_legacy=false, we leave the version empty and let the GUI layer set it to the latest version + + // Remove the old setting + erase("app", "legacy_networking"); + } + #ifdef __APPLE__ if (get("use_retina_opengl").empty()) set_bool("use_retina_opengl", true); @@ -278,9 +297,6 @@ void AppConfig::set_defaults() if (get("allow_abnormal_storage").empty()) { set_bool("allow_abnormal_storage", false); } - if (get("legacy_networking").empty()) { - set_bool("legacy_networking", false); - } if(get("check_stable_update_only").empty()) { set_bool("check_stable_update_only", false); diff --git a/src/libslic3r/AppConfig.hpp b/src/libslic3r/AppConfig.hpp index 82d87677ac..b521410ce9 100644 --- a/src/libslic3r/AppConfig.hpp +++ b/src/libslic3r/AppConfig.hpp @@ -28,6 +28,7 @@ using namespace nlohmann; #define SETTING_NETWORK_PLUGIN_SKIPPED_VERSIONS "network_plugin_skipped_versions" #define SETTING_NETWORK_PLUGIN_UPDATE_DISABLED "network_plugin_update_prompts_disabled" #define SETTING_NETWORK_PLUGIN_REMIND_LATER "network_plugin_remind_later" +#define BAMBU_NETWORK_AGENT_VERSION_LEGACY "01.10.01.01" #define SUPPORT_DARK_MODE //#define _MSW_DARK_MODE diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index 9edf8553dc..c0293d9e17 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -2903,8 +2903,11 @@ bool GUI_App::on_init_inner() std::map extra_headers = get_extra_header(); Slic3r::Http::set_extra_headers(extra_headers); - // Orca: select network plugin version - NetworkAgent::use_legacy_network = app_config->get_bool("legacy_networking"); + // Orca: select network plugin version based on configured version string + std::string configured_version = app_config->get_network_plugin_version(); + NetworkAgent::use_legacy_network = (configured_version == BAMBU_NETWORK_AGENT_VERSION_LEGACY); + BOOST_LOG_TRIVIAL(info) << "Network plugin mode: " + << (NetworkAgent::use_legacy_network ? ("legacy (version: " + std::string(BAMBU_NETWORK_AGENT_VERSION_LEGACY) + ")") : ("modern (version: " + configured_version + ")")); // Force legacy network plugin if debugger attached // See https://github.com/bambulab/BambuStudio/issues/6726 /* if (!NetworkAgent::use_legacy_network) { @@ -3202,13 +3205,6 @@ bool GUI_App::on_init_network(bool try_backup) std::string config_version = app_config->get_network_plugin_version(); - if (should_load_networking_plugin && Slic3r::NetworkAgent::legacy_library_exists() && config_version.empty()) { - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": migration: legacy library found with no config version, removing and requesting download"; - Slic3r::NetworkAgent::remove_legacy_library(); - m_networking_need_update = true; - return false; - } - if(!should_load_networking_plugin) { BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << "Don't load plugin as installed_networking is false"; } else { diff --git a/src/slic3r/GUI/Preferences.cpp b/src/slic3r/GUI/Preferences.cpp index abcf4d2af4..7dc2329f21 100644 --- a/src/slic3r/GUI/Preferences.cpp +++ b/src/slic3r/GUI/Preferences.cpp @@ -884,7 +884,6 @@ wxBoxSizer *PreferencesDialog::create_item_checkbox(wxString title, wxString too if (pbool) { GUI::wxGetApp().CallAfter([] { GUI::wxGetApp().ShowDownNetPluginDlg(); }); } - if (m_legacy_networking_ckeckbox != nullptr) { m_legacy_networking_ckeckbox->Enable(pbool); } } #endif // __WXMSW__ @@ -946,25 +945,12 @@ wxBoxSizer *PreferencesDialog::create_item_checkbox(wxString title, wxString too } } - if (param == "legacy_networking") { - bool legacy_mode = checkbox->GetValue(); - if (m_network_version_sizer != nullptr) { - m_network_version_sizer->Show(!legacy_mode); - m_parent->Layout(); - } - } - e.Skip(); }); //// for debug mode if (param == "developer_mode") { m_developer_mode_ckeckbox = checkbox; } if (param == "internal_developer_mode") { m_internal_developer_mode_ckeckbox = checkbox; } - if (param == "legacy_networking") { - m_legacy_networking_ckeckbox = checkbox; - bool pbool = app_config->get_bool("installed_networking"); - checkbox->Enable(pbool); - } return m_sizer_checkbox; } @@ -1424,9 +1410,6 @@ void PreferencesDialog::create_items() auto item_enable_plugin = create_item_checkbox(_L("Enable network plugin"), "", "installed_networking"); g_sizer->Add(item_enable_plugin); - - auto item_legacy_network = create_item_checkbox(_L("Use legacy network plugin"), _L("Disable to use latest network plugin that supports new BambuLab firmwares."), "legacy_networking", _L("(Requires restart)")); - g_sizer->Add(item_legacy_network); m_network_version_sizer = new wxBoxSizer(wxHORIZONTAL); m_network_version_sizer->AddSpacer(FromDIP(DESIGN_LEFT_MARGIN)); @@ -1442,7 +1425,10 @@ void PreferencesDialog::create_items() m_network_version_combo->SetFont(::Label::Body_14); m_network_version_combo->GetDropDown().SetFont(::Label::Body_14); - std::string current_version = app_config->get("network_plugin_version"); + std::string current_version = app_config->get_network_plugin_version(); + if (current_version.empty()) { + current_version = BBL::get_latest_network_version(); + } int current_selection = 0; m_available_versions = BBL::get_all_available_versions(); @@ -1485,16 +1471,26 @@ void PreferencesDialog::create_items() if (new_version != old_version) { BOOST_LOG_TRIVIAL(info) << "Network plugin version changed from " << old_version << " to " << new_version; + // Update the use_legacy_network flag immediately + bool is_legacy = (new_version == BAMBU_NETWORK_AGENT_VERSION_LEGACY); + bool was_legacy = (old_version == BAMBU_NETWORK_AGENT_VERSION_LEGACY); + if (is_legacy != was_legacy) { + Slic3r::NetworkAgent::use_legacy_network = is_legacy; + BOOST_LOG_TRIVIAL(info) << "Updated use_legacy_network flag to " << is_legacy; + } + if (!selected_ver.warning.empty()) { MessageDialog warn_dlg(this, wxString::FromUTF8(selected_ver.warning), _L("Warning"), wxOK | wxCANCEL | wxICON_WARNING); if (warn_dlg.ShowModal() != wxID_OK) { app_config->set(SETTING_NETWORK_PLUGIN_VERSION, old_version); app_config->save(); + Slic3r::NetworkAgent::use_legacy_network = was_legacy; e.Skip(); return; } } + // Check if the selected version already exists on disk if (Slic3r::NetworkAgent::versioned_library_exists(new_version)) { BOOST_LOG_TRIVIAL(info) << "Version " << new_version << " already exists on disk, triggering hot reload"; if (wxGetApp().hot_reload_network_plugin()) { @@ -1520,8 +1516,6 @@ void PreferencesDialog::create_items() e.Skip(); }); - bool legacy_mode = app_config->get_bool("legacy_networking"); - m_network_version_sizer->Show(!legacy_mode); g_sizer->Add(m_network_version_sizer); g_sizer->AddSpacer(FromDIP(10)); diff --git a/src/slic3r/GUI/Preferences.hpp b/src/slic3r/GUI/Preferences.hpp index 53182fd475..5f98174bf2 100644 --- a/src/slic3r/GUI/Preferences.hpp +++ b/src/slic3r/GUI/Preferences.hpp @@ -68,7 +68,6 @@ public: ::CheckBox * m_internal_developer_mode_ckeckbox = {nullptr}; ::CheckBox * m_dark_mode_ckeckbox = {nullptr}; ::TextInput *m_backup_interval_textinput = {nullptr}; - ::CheckBox * m_legacy_networking_ckeckbox = {nullptr}; ::ComboBox * m_network_version_combo = {nullptr}; wxBoxSizer * m_network_version_sizer = {nullptr}; std::vector m_available_versions; diff --git a/src/slic3r/Utils/NetworkAgent.cpp b/src/slic3r/Utils/NetworkAgent.cpp index cbbc645682..8220105f10 100644 --- a/src/slic3r/Utils/NetworkAgent.cpp +++ b/src/slic3r/Utils/NetworkAgent.cpp @@ -241,7 +241,17 @@ bool NetworkAgent::versioned_library_exists(const std::string& version) { if (version.empty()) return false; std::string path = get_versioned_library_path(version); - return boost::filesystem::exists(path); + + // Check if versioned library exists + if (boost::filesystem::exists(path)) return true; + + // For legacy version, also check if unversioned legacy library exists + // (it will be auto-migrated to versioned format when loaded) + if (version == BAMBU_NETWORK_AGENT_VERSION_LEGACY) { + return legacy_library_exists(); + } + + return false; } bool NetworkAgent::legacy_library_exists() @@ -353,9 +363,50 @@ int NetworkAgent::initialize_network_module(bool using_backup, const std::string return -1; } + // Auto-migration: If loading legacy version and versioned library doesn't exist, + // but unversioned legacy library does exist, rename it to versioned format + if (version == BAMBU_NETWORK_AGENT_VERSION_LEGACY) { + boost::filesystem::path versioned_path; + boost::filesystem::path legacy_path; +#if defined(_MSC_VER) || defined(_WIN32) + versioned_path = plugin_folder / (std::string(BAMBU_NETWORK_LIBRARY) + "_" + version + ".dll"); + legacy_path = plugin_folder / (std::string(BAMBU_NETWORK_LIBRARY) + ".dll"); +#elif defined(__WXMAC__) + versioned_path = plugin_folder / (std::string("lib") + std::string(BAMBU_NETWORK_LIBRARY) + "_" + version + ".dylib"); + legacy_path = plugin_folder / (std::string("lib") + std::string(BAMBU_NETWORK_LIBRARY) + ".dylib"); +#else + versioned_path = plugin_folder / (std::string("lib") + std::string(BAMBU_NETWORK_LIBRARY) + "_" + version + ".so"); + legacy_path = plugin_folder / (std::string("lib") + std::string(BAMBU_NETWORK_LIBRARY) + ".so"); +#endif + if (!boost::filesystem::exists(versioned_path) && boost::filesystem::exists(legacy_path)) { + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": auto-migrating unversioned legacy library to versioned format"; + + try { + // Rename unversioned to versioned in the same folder (main or backup). + boost::filesystem::rename(legacy_path, versioned_path); + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": successfully renamed " << legacy_path.string() << " to " + << versioned_path.string(); + } catch (const std::exception& e) { + BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ": failed to rename legacy library: " << e.what(); + } + } + } + + // Load versioned library #if defined(_MSC_VER) || defined(_WIN32) library = plugin_folder.string() + "\\" + std::string(BAMBU_NETWORK_LIBRARY) + "_" + version + ".dll"; BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": loading versioned library at " << library; +#else + #if defined(__WXMAC__) + std::string lib_ext = ".dylib"; + #else + std::string lib_ext = ".so"; + #endif + library = plugin_folder.string() + "/" + std::string("lib") + std::string(BAMBU_NETWORK_LIBRARY) + "_" + version + lib_ext; + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": loading versioned library at " << library; +#endif + +#if defined(_MSC_VER) || defined(_WIN32) wchar_t lib_wstr[256]; memset(lib_wstr, 0, sizeof(lib_wstr)); ::MultiByteToWideChar(CP_UTF8, NULL, library.c_str(), strlen(library.c_str())+1, lib_wstr, sizeof(lib_wstr) / sizeof(lib_wstr[0])); @@ -378,15 +429,6 @@ int NetworkAgent::initialize_network_module(bool using_backup, const std::string netwoking_module = LoadLibrary(lib_wstr); } #else - #if defined(__WXMAC__) - std::string lib_ext = ".dylib"; - #else - std::string lib_ext = ".so"; - #endif - - library = plugin_folder.string() + "/" + std::string("lib") + std::string(BAMBU_NETWORK_LIBRARY) + "_" + version + lib_ext; - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": loading versioned library at " << library; - netwoking_module = dlopen(library.c_str(), RTLD_LAZY); if (!netwoking_module) { char* dll_error = dlerror(); diff --git a/src/slic3r/Utils/bambu_networking.hpp b/src/slic3r/Utils/bambu_networking.hpp index b9a5b6b225..e9f756e705 100644 --- a/src/slic3r/Utils/bambu_networking.hpp +++ b/src/slic3r/Utils/bambu_networking.hpp @@ -6,6 +6,7 @@ #include #include +#include "libslic3r/AppConfig.hpp" extern std::string g_log_folder; extern std::string g_log_start_time; @@ -98,7 +99,6 @@ namespace BBL { #define BAMBU_NETWORK_LIBRARY "bambu_networking" #define BAMBU_NETWORK_AGENT_NAME "bambu_network_agent" -#define BAMBU_NETWORK_AGENT_VERSION_LEGACY "01.10.01.01" //iot preset type strings #define IOT_PRINTER_TYPE_STRING "printer" @@ -318,6 +318,7 @@ static const NetworkLibraryVersion AVAILABLE_NETWORK_VERSIONS[] = { {"02.03.00.62", "02.03.00.62", nullptr, true, nullptr}, {"02.01.01.52", "02.01.01.52", nullptr, false, nullptr}, {"02.00.02.50", "02.00.02.50", nullptr, false, "This version may crash on startup due to Bambu Lab's signature verification."}, + {BAMBU_NETWORK_AGENT_VERSION_LEGACY, BAMBU_NETWORK_AGENT_VERSION_LEGACY " (legacy)", nullptr, false, "Legacy version - may not support newer firmware features. Only use if you have issues with modern versions."}, }; static const size_t AVAILABLE_NETWORK_VERSIONS_COUNT = sizeof(AVAILABLE_NETWORK_VERSIONS) / sizeof(AVAILABLE_NETWORK_VERSIONS[0]);