mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-08 07:27:41 -06:00
ENH: Updater: always update plugin to the newest compatible version
Change-Id: Icec343ba4913b9738add9564c78934553a33336c
This commit is contained in:
parent
9d85a7f216
commit
fcf490028a
4 changed files with 115 additions and 14 deletions
|
@ -1096,7 +1096,8 @@ void GUI_App::post_init()
|
||||||
|
|
||||||
std::string http_url = get_http_url(app_config->get_country_code());
|
std::string http_url = get_http_url(app_config->get_country_code());
|
||||||
std::string language = GUI::into_u8(current_language_code());
|
std::string language = GUI::into_u8(current_language_code());
|
||||||
this->preset_updater->sync(http_url, language, preset_bundle);
|
std::string network_ver = Slic3r::NetworkAgent::get_version();
|
||||||
|
this->preset_updater->sync(http_url, language, network_ver, preset_bundle);
|
||||||
|
|
||||||
//BBS: check new version
|
//BBS: check new version
|
||||||
this->check_new_version();
|
this->check_new_version();
|
||||||
|
@ -2224,6 +2225,7 @@ bool GUI_App::on_init_inner()
|
||||||
|
|
||||||
Bind(EVT_USER_LOGIN, &GUI_App::on_user_login, this);
|
Bind(EVT_USER_LOGIN, &GUI_App::on_user_login, this);
|
||||||
|
|
||||||
|
copy_network_if_available();
|
||||||
on_init_network();
|
on_init_network();
|
||||||
|
|
||||||
//BBS if load user preset failed
|
//BBS if load user preset failed
|
||||||
|
@ -2385,6 +2387,59 @@ bool GUI_App::on_init_inner()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GUI_App::copy_network_if_available()
|
||||||
|
{
|
||||||
|
std::string network_library, player_library, network_library_dst, player_library_dst;
|
||||||
|
std::string data_dir_str = data_dir();
|
||||||
|
boost::filesystem::path data_dir_path(data_dir_str);
|
||||||
|
auto plugin_folder = data_dir_path / "plugins";
|
||||||
|
auto cache_folder = data_dir_path / "ota";
|
||||||
|
#if defined(_MSC_VER) || defined(_WIN32)
|
||||||
|
network_library = cache_folder.string() + "/bambu_networking.dll";
|
||||||
|
player_library = cache_folder.string() + "/BambuSource.dll";
|
||||||
|
network_library_dst = plugin_folder.string() + "/bambu_networking.dll";
|
||||||
|
player_library_dst = plugin_folder.string() + "/BambuSource.dll";
|
||||||
|
#elif defined(__WXMAC__)
|
||||||
|
network_library = cache_folder.string() + "/libbambu_networking.dylib";
|
||||||
|
player_library = cache_folder.string() + "/libBambuSource.dylib";
|
||||||
|
network_library_dst = plugin_folder.string() + "/libbambu_networking.dylib";
|
||||||
|
player_library_dst = plugin_folder.string() + "/libBambuSource.dylib";
|
||||||
|
#else
|
||||||
|
network_library = cache_folder.string() + "/libbambu_networking.so";
|
||||||
|
player_library = cache_folder.string() + "/libBambuSource.so";
|
||||||
|
network_library_dst = plugin_folder.string() + "/libbambu_networking.so";
|
||||||
|
player_library_dst = plugin_folder.string() + "/libBambuSource.so";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
BOOST_LOG_TRIVIAL(info) << __FUNCTION__<< ": checking network_library " << network_library << ", player_library " << player_library;
|
||||||
|
std::string error_message;
|
||||||
|
if (boost::filesystem::exists(network_library)) {
|
||||||
|
CopyFileResult cfr = copy_file(network_library, network_library_dst, error_message, false);
|
||||||
|
if (cfr != CopyFileResult::SUCCESS) {
|
||||||
|
BOOST_LOG_TRIVIAL(error) << __FUNCTION__<< ": Copying failed(" << cfr << "): " << error_message;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
static constexpr const auto perms = fs::owner_read | fs::owner_write | fs::group_read | fs::others_read;
|
||||||
|
fs::permissions(network_library_dst, perms);
|
||||||
|
fs::remove(network_library);
|
||||||
|
BOOST_LOG_TRIVIAL(info) << __FUNCTION__<< ": Copying network library from" << network_library << " to " << network_library_dst<<" successfully.";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (boost::filesystem::exists(player_library)) {
|
||||||
|
CopyFileResult cfr = copy_file(player_library, player_library_dst, error_message, false);
|
||||||
|
if (cfr != CopyFileResult::SUCCESS) {
|
||||||
|
BOOST_LOG_TRIVIAL(error) << __FUNCTION__<< ": Copying failed(" << cfr << "): " << error_message;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
static constexpr const auto perms = fs::owner_read | fs::owner_write | fs::group_read | fs::others_read;
|
||||||
|
fs::permissions(player_library_dst, perms);
|
||||||
|
fs::remove(player_library);
|
||||||
|
BOOST_LOG_TRIVIAL(info) << __FUNCTION__<< ": Copying player library from" << player_library << " to " << player_library_dst<<" successfully.";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool GUI_App::on_init_network(bool try_backup)
|
bool GUI_App::on_init_network(bool try_backup)
|
||||||
{
|
{
|
||||||
int load_agent_dll = Slic3r::NetworkAgent::initialize_network_module();
|
int load_agent_dll = Slic3r::NetworkAgent::initialize_network_module();
|
||||||
|
|
|
@ -536,6 +536,7 @@ public:
|
||||||
private:
|
private:
|
||||||
int updating_bambu_networking();
|
int updating_bambu_networking();
|
||||||
bool on_init_inner();
|
bool on_init_inner();
|
||||||
|
void copy_network_if_available();
|
||||||
bool on_init_network(bool try_backup = false);
|
bool on_init_network(bool try_backup = false);
|
||||||
void init_networking_callbacks();
|
void init_networking_callbacks();
|
||||||
void init_app_config();
|
void init_app_config();
|
||||||
|
|
|
@ -230,9 +230,10 @@ struct PresetUpdater::priv
|
||||||
void prune_tmps() const;
|
void prune_tmps() const;
|
||||||
void sync_version() const;
|
void sync_version() const;
|
||||||
void parse_version_string(const std::string& body) const;
|
void parse_version_string(const std::string& body) const;
|
||||||
void sync_resources(std::string http_url, std::map<std::string, Resource> &resources);
|
void sync_resources(std::string http_url, std::map<std::string, Resource> &resources, bool check_patch = false, std::string current_version="");
|
||||||
void sync_config(std::string http_url, const VendorMap vendors);
|
void sync_config(std::string http_url, const VendorMap vendors);
|
||||||
void sync_tooltip(std::string http_url, std::string language);
|
void sync_tooltip(std::string http_url, std::string language);
|
||||||
|
void sync_plugins(std::string http_url, std::string plugin_version);
|
||||||
|
|
||||||
//BBS: refine preset update logic
|
//BBS: refine preset update logic
|
||||||
bool install_bundles_rsrc(std::vector<std::string> bundles, bool snapshot) const;
|
bool install_bundles_rsrc(std::vector<std::string> bundles, bool snapshot) const;
|
||||||
|
@ -349,6 +350,7 @@ bool PresetUpdater::priv::extract_file(const fs::path &source_path, const fs::pa
|
||||||
close_zip_reader(&archive);
|
close_zip_reader(&archive);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
BOOST_LOG_TRIVIAL(info) << "[BBL Updater]successfully extract file " << stat.m_file_index << " to "<<dest_file;
|
||||||
}
|
}
|
||||||
catch (const std::exception& e)
|
catch (const std::exception& e)
|
||||||
{
|
{
|
||||||
|
@ -479,11 +481,11 @@ void PresetUpdater::priv::parse_version_string(const std::string& body) const
|
||||||
//BBS: refine the Preset Updater logic
|
//BBS: refine the Preset Updater logic
|
||||||
// Download vendor indices. Also download new bundles if an index indicates there's a new one available.
|
// Download vendor indices. Also download new bundles if an index indicates there's a new one available.
|
||||||
// Both are saved in cache.
|
// Both are saved in cache.
|
||||||
void PresetUpdater::priv::sync_resources(std::string http_url, std::map<std::string, Resource> &resources)
|
void PresetUpdater::priv::sync_resources(std::string http_url, std::map<std::string, Resource> &resources, bool check_patch, std::string current_version_str)
|
||||||
{
|
{
|
||||||
std::map<std::string, Resource> resource_list;
|
std::map<std::string, Resource> resource_list;
|
||||||
|
|
||||||
BOOST_LOG_TRIVIAL(info) << boost::format("[BBL Updater]: sync_resources get preferred setting version for app version %1%, url: %2%")%SLIC3R_APP_NAME%http_url;
|
BOOST_LOG_TRIVIAL(info) << boost::format("[BBL Updater]: sync_resources get preferred setting version for app version %1%, url: %2%, current_version_str %3%, check_patch %4%")%SLIC3R_APP_NAME%http_url%current_version_str%check_patch;
|
||||||
|
|
||||||
std::string query_params = "?";
|
std::string query_params = "?";
|
||||||
bool first = true;
|
bool first = true;
|
||||||
|
@ -545,7 +547,7 @@ void PresetUpdater::priv::sync_resources(std::string http_url, std::map<std::str
|
||||||
} catch (std::exception &e) {
|
} catch (std::exception &e) {
|
||||||
BOOST_LOG_TRIVIAL(error) << (boost::format("[BBL Updater]: get version of settings failed, exception=%1% body=%2%") % e.what() % body).str();
|
BOOST_LOG_TRIVIAL(error) << (boost::format("[BBL Updater]: get version of settings failed, exception=%1% body=%2%") % e.what() % body).str();
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
BOOST_LOG_TRIVIAL(error) << "[BBL Updater]: get version of settings failed,, body=" << body;
|
BOOST_LOG_TRIVIAL(error) << "[BBL Updater]: get version of settings failed, body=" << body;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.on_error([&](std::string body, std::string error, unsigned status) {
|
.on_error([&](std::string body, std::string error, unsigned status) {
|
||||||
|
@ -566,8 +568,16 @@ void PresetUpdater::priv::sync_resources(std::string http_url, std::map<std::str
|
||||||
}
|
}
|
||||||
Semver online_version = resource_update->second.version;
|
Semver online_version = resource_update->second.version;
|
||||||
// Semver current_version = get_version_from_json(vendor_root_config.string());
|
// Semver current_version = get_version_from_json(vendor_root_config.string());
|
||||||
Semver current_version = resource.version;
|
Semver current_version = current_version_str.empty()?resource.version:current_version_str;
|
||||||
bool version_match = ((online_version.maj() == current_version.maj()) && (online_version.min() == current_version.min()));
|
bool version_match = ((online_version.maj() == current_version.maj()) && (online_version.min() == current_version.min()));
|
||||||
|
if (version_match && check_patch) {
|
||||||
|
int online_cc_patch = online_version.patch()/100;
|
||||||
|
int current_cc_patch = current_version.patch()/100;
|
||||||
|
if (online_cc_patch != current_cc_patch) {
|
||||||
|
version_match = false;
|
||||||
|
BOOST_LOG_TRIVIAL(warning) << boost::format("[BBL Updater]: online patch CC not match: online_cc_patch=%1%, current_cc_patch=%2%") % online_cc_patch % current_cc_patch;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (version_match && (current_version < online_version)) {
|
if (version_match && (current_version < online_version)) {
|
||||||
if (cancel) { return; }
|
if (cancel) { return; }
|
||||||
|
|
||||||
|
@ -584,14 +594,20 @@ void PresetUpdater::priv::sync_resources(std::string http_url, std::map<std::str
|
||||||
|
|
||||||
// remove previous files before
|
// remove previous files before
|
||||||
if (resource.sub_caches.empty()) {
|
if (resource.sub_caches.empty()) {
|
||||||
if (fs::exists(cache_path)) fs::remove_all(cache_path);
|
if (fs::exists(cache_path)) {
|
||||||
|
fs::remove_all(cache_path);
|
||||||
|
BOOST_LOG_TRIVIAL(info) << "[BBL Updater]remove cache path " << cache_path.string();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
for (auto sub : resource.sub_caches) {
|
for (auto sub : resource.sub_caches) {
|
||||||
if (fs::exists(cache_path / sub)) fs::remove_all(cache_path / sub);
|
if (fs::exists(cache_path / sub)) {
|
||||||
|
fs::remove_all(cache_path / sub);
|
||||||
|
BOOST_LOG_TRIVIAL(info) << "[BBL Updater]remove cache path " << (cache_path / sub).string();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// extract the file downloaded
|
// extract the file downloaded
|
||||||
BOOST_LOG_TRIVIAL(info) << "[BBL Updater]start to unzip the downloaded file " << cache_file_path;
|
BOOST_LOG_TRIVIAL(info) << "[BBL Updater]start to unzip the downloaded file " << cache_file_path << " to "<<cache_path;
|
||||||
fs::create_directories(cache_path);
|
fs::create_directories(cache_path);
|
||||||
if (!extract_file(cache_file_path, cache_path)) {
|
if (!extract_file(cache_file_path, cache_path)) {
|
||||||
BOOST_LOG_TRIVIAL(warning) << "[BBL Updater]extract resource " << resource_it.first << " failed, path: " << cache_file_path;
|
BOOST_LOG_TRIVIAL(warning) << "[BBL Updater]extract resource " << resource_it.first << " failed, path: " << cache_file_path;
|
||||||
|
@ -611,6 +627,9 @@ void PresetUpdater::priv::sync_resources(std::string http_url, std::map<std::str
|
||||||
|
|
||||||
resource_it.second = resource_update->second;
|
resource_it.second = resource_update->second;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
BOOST_LOG_TRIVIAL(warning) << boost::format("[BBL Updater]: online version=%1%, current_version=%2%, no need to download") % online_version.to_string() % current_version.to_string();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -830,6 +849,28 @@ void PresetUpdater::priv::sync_tooltip(std::string http_url, std::string languag
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PresetUpdater::priv::sync_plugins(std::string http_url, std::string plugin_version)
|
||||||
|
{
|
||||||
|
if (plugin_version == "00.00.00.00") {
|
||||||
|
BOOST_LOG_TRIVIAL(info) << "non need to sync plugins for there is no plugins currently.";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
std::string curr_version = SLIC3R_VERSION;
|
||||||
|
std::string using_version = curr_version.substr(0, 9) + "00";
|
||||||
|
|
||||||
|
try {
|
||||||
|
std::map<std::string, Resource> resources
|
||||||
|
{
|
||||||
|
{"slicer/plugins/cloud", { using_version, "", "", cache_path.string(), {"plugins"}}}
|
||||||
|
};
|
||||||
|
sync_resources(http_url, resources, true, plugin_version);
|
||||||
|
}
|
||||||
|
catch (std::exception& e) {
|
||||||
|
BOOST_LOG_TRIVIAL(warning) << format("[BBL Updater] sync_plugins: %1%", e.what());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool PresetUpdater::priv::install_bundles_rsrc(std::vector<std::string> bundles, bool snapshot) const
|
bool PresetUpdater::priv::install_bundles_rsrc(std::vector<std::string> bundles, bool snapshot) const
|
||||||
{
|
{
|
||||||
Updates updates;
|
Updates updates;
|
||||||
|
@ -1092,7 +1133,7 @@ PresetUpdater::~PresetUpdater()
|
||||||
|
|
||||||
//BBS: change directories by design
|
//BBS: change directories by design
|
||||||
//BBS: refine the preset updater logic
|
//BBS: refine the preset updater logic
|
||||||
void PresetUpdater::sync(std::string http_url, std::string language, PresetBundle *preset_bundle)
|
void PresetUpdater::sync(std::string http_url, std::string language, std::string plugin_version, PresetBundle *preset_bundle)
|
||||||
{
|
{
|
||||||
//p->set_download_prefs(GUI::wxGetApp().app_config);
|
//p->set_download_prefs(GUI::wxGetApp().app_config);
|
||||||
if (!p->enabled_version_check && !p->enabled_config_update) { return; }
|
if (!p->enabled_version_check && !p->enabled_config_update) { return; }
|
||||||
|
@ -1102,7 +1143,7 @@ void PresetUpdater::sync(std::string http_url, std::string language, PresetBundl
|
||||||
// into the closure (but perhaps the compiler can elide this).
|
// into the closure (but perhaps the compiler can elide this).
|
||||||
VendorMap vendors = preset_bundle->vendors;
|
VendorMap vendors = preset_bundle->vendors;
|
||||||
|
|
||||||
p->thread = std::thread([this, vendors, http_url, language]() {
|
p->thread = std::thread([this, vendors, http_url, language, plugin_version]() {
|
||||||
this->p->prune_tmps();
|
this->p->prune_tmps();
|
||||||
if (p->cancel)
|
if (p->cancel)
|
||||||
return;
|
return;
|
||||||
|
@ -1112,8 +1153,12 @@ void PresetUpdater::sync(std::string http_url, std::string language, PresetBundl
|
||||||
this->p->sync_config(http_url, std::move(vendors));
|
this->p->sync_config(http_url, std::move(vendors));
|
||||||
if (p->cancel)
|
if (p->cancel)
|
||||||
return;
|
return;
|
||||||
this->p->sync_tooltip(http_url, language);
|
this->p->sync_plugins(http_url, plugin_version);
|
||||||
});
|
//if (p->cancel)
|
||||||
|
// return;
|
||||||
|
//remove the tooltip currently
|
||||||
|
//this->p->sync_tooltip(http_url, language);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void PresetUpdater::slic3r_update_notify()
|
void PresetUpdater::slic3r_update_notify()
|
||||||
|
|
|
@ -26,7 +26,7 @@ public:
|
||||||
~PresetUpdater();
|
~PresetUpdater();
|
||||||
|
|
||||||
// If either version check or config updating is enabled, get the appropriate data in the background and cache it.
|
// If either version check or config updating is enabled, get the appropriate data in the background and cache it.
|
||||||
void sync(std::string http_url, std::string language, PresetBundle *preset_bundle);
|
void sync(std::string http_url, std::string language, std::string plugin_version, PresetBundle *preset_bundle);
|
||||||
|
|
||||||
// If version check is enabled, check if chaced online slic3r version is newer, notify if so.
|
// If version check is enabled, check if chaced online slic3r version is newer, notify if so.
|
||||||
void slic3r_update_notify();
|
void slic3r_update_notify();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue