mirror of
https://git.mirrors.martin98.com/https://github.com/bambulab/BambuStudio.git
synced 2025-09-21 04:23:15 +08:00
FIX: updater: fix force upgrade logic
JIRA: STUDIO-6393 Change-Id: I46c51e09e7390e5ab0de40215911aac9635ab476 (cherry picked from commit 673ba6ff4ebda039d71dcbfdaa28c1252f5b8821)
This commit is contained in:
parent
023c1ef7cb
commit
e931bd8ab4
@ -220,6 +220,7 @@ struct PresetUpdater::priv
|
|||||||
std::string version;
|
std::string version;
|
||||||
std::string description;
|
std::string description;
|
||||||
std::string url;
|
std::string url;
|
||||||
|
bool force{false};
|
||||||
std::string cache_root;
|
std::string cache_root;
|
||||||
std::vector<std::string> sub_caches;
|
std::vector<std::string> sub_caches;
|
||||||
};
|
};
|
||||||
@ -238,7 +239,7 @@ struct PresetUpdater::priv
|
|||||||
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);
|
void sync_plugins(std::string http_url, std::string plugin_version);
|
||||||
void sync_printer_config(std::string http_url);
|
void sync_printer_config(std::string http_url);
|
||||||
bool get_cached_plugins_version(std::string &cached_version);
|
bool get_cached_plugins_version(std::string &cached_version, bool& force);
|
||||||
|
|
||||||
//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;
|
||||||
@ -531,6 +532,7 @@ void PresetUpdater::priv::sync_resources(std::string http_url, std::map<std::str
|
|||||||
std::string url;
|
std::string url;
|
||||||
std::string resource;
|
std::string resource;
|
||||||
std::string description;
|
std::string description;
|
||||||
|
bool force_upgrade = false;
|
||||||
for (auto sub_iter = iter.value().begin(); sub_iter != iter.value().end(); sub_iter++) {
|
for (auto sub_iter = iter.value().begin(); sub_iter != iter.value().end(); sub_iter++) {
|
||||||
if (boost::iequals(sub_iter.key(), "type")) {
|
if (boost::iequals(sub_iter.key(), "type")) {
|
||||||
resource = sub_iter.value();
|
resource = sub_iter.value();
|
||||||
@ -542,10 +544,13 @@ void PresetUpdater::priv::sync_resources(std::string http_url, std::map<std::str
|
|||||||
} else if (boost::iequals(sub_iter.key(), "url")) {
|
} else if (boost::iequals(sub_iter.key(), "url")) {
|
||||||
url = sub_iter.value();
|
url = sub_iter.value();
|
||||||
}
|
}
|
||||||
|
else if (boost::iequals(sub_iter.key(), "force_update")) {
|
||||||
|
force_upgrade = sub_iter.value();
|
||||||
}
|
}
|
||||||
BOOST_LOG_TRIVIAL(info) << "[BBL Updater]: get type " << resource << ", version " << version << ", url " << url;
|
}
|
||||||
|
BOOST_LOG_TRIVIAL(info) << "[BBL Updater]: get type " << resource << ", version " << version << ", url " << url<<", force_update "<<force_upgrade;
|
||||||
|
|
||||||
resource_list.emplace(resource, Resource{version, description, url});
|
resource_list.emplace(resource, Resource{version, description, url, force_upgrade});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -633,6 +638,7 @@ void PresetUpdater::priv::sync_resources(std::string http_url, std::map<std::str
|
|||||||
//record the headers
|
//record the headers
|
||||||
j["version"] = resource_update->second.version;
|
j["version"] = resource_update->second.version;
|
||||||
j["description"] = resource_update->second.description;
|
j["description"] = resource_update->second.description;
|
||||||
|
j["force"] = resource_update->second.force;
|
||||||
|
|
||||||
boost::nowide::ofstream c;
|
boost::nowide::ofstream c;
|
||||||
c.open(changelog_file, std::ios::out | std::ios::trunc);
|
c.open(changelog_file, std::ios::out | std::ios::trunc);
|
||||||
@ -878,8 +884,8 @@ void PresetUpdater::priv::sync_tooltip(std::string http_url, std::string languag
|
|||||||
} catch (...) {}
|
} catch (...) {}
|
||||||
std::map<std::string, Resource> resources
|
std::map<std::string, Resource> resources
|
||||||
{
|
{
|
||||||
{"slicer/tooltip/common", { common_version, "", "", (cache_root / "common").string() }},
|
{"slicer/tooltip/common", { common_version, "", "", false, (cache_root / "common").string() }},
|
||||||
{"slicer/tooltip/" + language, { language_version, "", "", (cache_root / language).string() }}
|
{"slicer/tooltip/" + language, { language_version, "", "", false, (cache_root / language).string() }}
|
||||||
};
|
};
|
||||||
sync_resources(http_url, resources);
|
sync_resources(http_url, resources);
|
||||||
for (auto &r : resources) {
|
for (auto &r : resources) {
|
||||||
@ -895,7 +901,7 @@ void PresetUpdater::priv::sync_tooltip(std::string http_url, std::string languag
|
|||||||
}
|
}
|
||||||
|
|
||||||
// return true means there are plugins files
|
// return true means there are plugins files
|
||||||
bool PresetUpdater::priv::get_cached_plugins_version(std::string& cached_version)
|
bool PresetUpdater::priv::get_cached_plugins_version(std::string& cached_version, bool &force)
|
||||||
{
|
{
|
||||||
std::string data_dir_str = data_dir();
|
std::string data_dir_str = data_dir();
|
||||||
boost::filesystem::path data_dir_path(data_dir_str);
|
boost::filesystem::path data_dir_path(data_dir_str);
|
||||||
@ -929,6 +935,7 @@ bool PresetUpdater::priv::get_cached_plugins_version(std::string& cached_version
|
|||||||
ifs >> j;
|
ifs >> j;
|
||||||
|
|
||||||
cached_version = j["version"];
|
cached_version = j["version"];
|
||||||
|
force = j["force"];
|
||||||
}
|
}
|
||||||
catch(nlohmann::detail::parse_error &err) {
|
catch(nlohmann::detail::parse_error &err) {
|
||||||
BOOST_LOG_TRIVIAL(error) << __FUNCTION__<< ": parse "<<changelog_file<<" got a nlohmann::detail::parse_error, reason = " << err.what();
|
BOOST_LOG_TRIVIAL(error) << __FUNCTION__<< ": parse "<<changelog_file<<" got a nlohmann::detail::parse_error, reason = " << err.what();
|
||||||
@ -949,7 +956,8 @@ void PresetUpdater::priv::sync_plugins(std::string http_url, std::string plugin_
|
|||||||
std::string using_version = curr_version.substr(0, 9) + "00";
|
std::string using_version = curr_version.substr(0, 9) + "00";
|
||||||
|
|
||||||
std::string cached_version;
|
std::string cached_version;
|
||||||
get_cached_plugins_version(cached_version);
|
bool force_upgrade = false;
|
||||||
|
get_cached_plugins_version(cached_version, force_upgrade);
|
||||||
if (!cached_version.empty()) {
|
if (!cached_version.empty()) {
|
||||||
bool need_delete_cache = false;
|
bool need_delete_cache = false;
|
||||||
Semver current_semver = curr_version;
|
Semver current_semver = curr_version;
|
||||||
@ -1042,7 +1050,7 @@ void PresetUpdater::priv::sync_plugins(std::string http_url, std::string plugin_
|
|||||||
try {
|
try {
|
||||||
std::map<std::string, Resource> resources
|
std::map<std::string, Resource> resources
|
||||||
{
|
{
|
||||||
{"slicer/plugins/cloud", { using_version, "", "", cache_path.string(), {"plugins"}}}
|
{"slicer/plugins/cloud", { using_version, "", "", false, cache_path.string(), {"plugins"}}}
|
||||||
};
|
};
|
||||||
sync_resources(http_url, resources, true, plugin_version, "network_plugins.json");
|
sync_resources(http_url, resources, true, plugin_version, "network_plugins.json");
|
||||||
}
|
}
|
||||||
@ -1050,9 +1058,17 @@ void PresetUpdater::priv::sync_plugins(std::string http_url, std::string plugin_
|
|||||||
BOOST_LOG_TRIVIAL(warning) << format("[BBL Updater] sync_plugins: %1%", e.what());
|
BOOST_LOG_TRIVIAL(warning) << format("[BBL Updater] sync_plugins: %1%", e.what());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool result = get_cached_plugins_version(cached_version);
|
bool result = get_cached_plugins_version(cached_version, force_upgrade);
|
||||||
if (result) {
|
if (result) {
|
||||||
BOOST_LOG_TRIVIAL(info) << format("[BBL Updater] found new plugins: %1%, prompt to update", cached_version);
|
BOOST_LOG_TRIVIAL(info) << format("[BBL Updater] found new plugins: %1%, prompt to update, force_upgrade %2%", cached_version, force_upgrade);
|
||||||
|
if (force_upgrade) {
|
||||||
|
auto app_config = GUI::wxGetApp().app_config;
|
||||||
|
if (!app_config)
|
||||||
|
GUI::wxGetApp().plater()->get_notification_manager()->push_notification(GUI::NotificationType::BBLPluginUpdateAvailable);
|
||||||
|
else
|
||||||
|
app_config->set("update_network_plugin", "true");
|
||||||
|
}
|
||||||
|
else
|
||||||
GUI::wxGetApp().plater()->get_notification_manager()->push_notification(GUI::NotificationType::BBLPluginUpdateAvailable);
|
GUI::wxGetApp().plater()->get_notification_manager()->push_notification(GUI::NotificationType::BBLPluginUpdateAvailable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1103,7 +1119,7 @@ void PresetUpdater::priv::sync_printer_config(std::string http_url)
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
std::map<std::string, Resource> resources{{"slicer/printer/bbl", {using_version, "", "", cache_folder.string()}}};
|
std::map<std::string, Resource> resources{{"slicer/printer/bbl", {using_version, "", "", false, cache_folder.string()}}};
|
||||||
sync_resources(http_url, resources, false, cached_version, "printer.json");
|
sync_resources(http_url, resources, false, cached_version, "printer.json");
|
||||||
} catch (std::exception &e) {
|
} catch (std::exception &e) {
|
||||||
BOOST_LOG_TRIVIAL(warning) << format("[BBL Updater] sync_printer_config: %1%", e.what());
|
BOOST_LOG_TRIVIAL(warning) << format("[BBL Updater] sync_printer_config: %1%", e.what());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user