add logic to remove the plugins folder when the version changed

Change-Id: Idb0ac34376c4eed81bf37da7afe670d9d9a42457
This commit is contained in:
lane.wei 2022-08-30 22:28:57 +08:00 committed by Lane.Wei
parent 562b52c6b9
commit b5a21e6520
2 changed files with 38 additions and 14 deletions

View File

@ -1482,6 +1482,19 @@ void GUI_App::restart_networking()
BOOST_LOG_TRIVIAL(info) << __FUNCTION__<< boost::format(" exit, m_agent=%1%")%m_agent;
}
void GUI_App::remove_old_networking_plugins()
{
auto plugin_folder = boost::filesystem::path(wxStandardPaths::Get().GetUserDataDir().ToUTF8().data()) / "plugins";
if (boost::filesystem::exists(plugin_folder)) {
BOOST_LOG_TRIVIAL(info) << "[remove_old_networking_plugins] remove the directory "<<plugin_folder.string();
try {
fs::remove_all(plugin_folder);
} catch (...) {
BOOST_LOG_TRIVIAL(error) << "Failed removing the plugins directory " << plugin_folder.string();
}
}
}
int GUI_App::updating_bambu_networking()
{
DownloadProgressDialog dlg(_L("Downloading Bambu Network Plug-in"));
@ -1911,10 +1924,20 @@ bool GUI_App::on_init_inner()
init_fonts();
if (m_last_config_version) {
if (*m_last_config_version < *Semver::parse(SLIC3R_VERSION))
check_older_app_config(*m_last_config_version, true);
} else {
check_older_app_config(Semver(), false);
int last_major = m_last_config_version->maj();
int last_minor = m_last_config_version->min();
int last_patch = m_last_config_version->patch()/100;
std::string studio_ver = SLIC3R_VERSION;
int cur_major = atoi(studio_ver.substr(0,2).c_str());
int cur_minor = atoi(studio_ver.substr(3,2).c_str());
int cur_patch = atoi(studio_ver.substr(6,2).c_str());
BOOST_LOG_TRIVIAL(info) << boost::format("last app version {%1%.%2%.%3%}, current version {%4%.%5%.%6%}")
%last_major%last_minor%last_patch%cur_major%cur_minor%cur_patch;
if ((last_major != cur_major)
||(last_minor != cur_minor)
||(last_patch != cur_patch)) {
remove_old_networking_plugins();
}
}
app_config->set("version", SLIC3R_VERSION);

View File

@ -526,6 +526,7 @@ private:
bool on_init_network(bool try_backup = false);
void init_networking_callbacks();
void init_app_config();
void remove_old_networking_plugins();
//BBS set extra header for http request
std::map<std::string, std::string> get_extra_header();
void init_http_extra_header();