mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-16 11:17:51 -06:00
add the backup logic to make sure plugin install success
Change-Id: Id9da725ffe2e6d604c2771abf89cf445824793db
This commit is contained in:
parent
a9e3bb59a0
commit
49fc813383
4 changed files with 37 additions and 5 deletions
|
@ -1332,10 +1332,15 @@ int GUI_App::install_plugin(InstallProgressFn pro_fn, WasCancelledFn cancel_fn)
|
||||||
BOOST_LOG_TRIVIAL(info) << "[install_plugin] enter";
|
BOOST_LOG_TRIVIAL(info) << "[install_plugin] enter";
|
||||||
// get plugin folder
|
// get plugin folder
|
||||||
auto plugin_folder = boost::filesystem::path(wxStandardPaths::Get().GetUserDataDir().ToUTF8().data()) / "plugins";
|
auto plugin_folder = boost::filesystem::path(wxStandardPaths::Get().GetUserDataDir().ToUTF8().data()) / "plugins";
|
||||||
|
auto backup_folder = plugin_folder/"backup";
|
||||||
if (!boost::filesystem::exists(plugin_folder)) {
|
if (!boost::filesystem::exists(plugin_folder)) {
|
||||||
BOOST_LOG_TRIVIAL(info) << "[install_plugin] will create directory "<<plugin_folder.string();
|
BOOST_LOG_TRIVIAL(info) << "[install_plugin] will create directory "<<plugin_folder.string();
|
||||||
boost::filesystem::create_directory(plugin_folder);
|
boost::filesystem::create_directory(plugin_folder);
|
||||||
}
|
}
|
||||||
|
if (!boost::filesystem::exists(backup_folder)) {
|
||||||
|
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", will create directory %1%")%backup_folder.string();
|
||||||
|
boost::filesystem::create_directory(backup_folder);
|
||||||
|
}
|
||||||
|
|
||||||
if (m_networking_cancel_update) {
|
if (m_networking_cancel_update) {
|
||||||
BOOST_LOG_TRIVIAL(info) << boost::format("[install_plugin]: %1%, cancelled by user")%__LINE__;
|
BOOST_LOG_TRIVIAL(info) << boost::format("[install_plugin]: %1%, cancelled by user")%__LINE__;
|
||||||
|
@ -1394,6 +1399,21 @@ int GUI_App::install_plugin(InstallProgressFn pro_fn, WasCancelledFn cancel_fn)
|
||||||
if (pro_fn) {
|
if (pro_fn) {
|
||||||
pro_fn(InstallStatusNormal, 50 + i/num_entries, cancel);
|
pro_fn(InstallStatusNormal, 50 + i/num_entries, cancel);
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
auto backup_path = boost::filesystem::path(backup_folder.string() + "/" + dest_file);
|
||||||
|
if (fs::exists(backup_path))
|
||||||
|
fs::remove(backup_path);
|
||||||
|
std::string error_message;
|
||||||
|
CopyFileResult cfr = copy_file(dest_path.string(), backup_path.string(), error_message, false);
|
||||||
|
if (cfr != CopyFileResult::SUCCESS) {
|
||||||
|
BOOST_LOG_TRIVIAL(error) << "Copying to backup failed(" << cfr << "): " << error_message;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (const std::exception& e)
|
||||||
|
{
|
||||||
|
BOOST_LOG_TRIVIAL(error) << "Copying to backup failed: " << e.what();
|
||||||
|
//continue
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (const std::exception& e)
|
catch (const std::exception& e)
|
||||||
|
@ -1425,7 +1445,7 @@ int GUI_App::install_plugin(InstallProgressFn pro_fn, WasCancelledFn cancel_fn)
|
||||||
void GUI_App::restart_networking()
|
void GUI_App::restart_networking()
|
||||||
{
|
{
|
||||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__<< boost::format(" enter, mainframe %1%")%mainframe;
|
BOOST_LOG_TRIVIAL(info) << __FUNCTION__<< boost::format(" enter, mainframe %1%")%mainframe;
|
||||||
on_init_network();
|
on_init_network(true);
|
||||||
if(m_agent) {
|
if(m_agent) {
|
||||||
init_networking_callbacks();
|
init_networking_callbacks();
|
||||||
m_agent->set_on_ssdp_msg_fn(
|
m_agent->set_on_ssdp_msg_fn(
|
||||||
|
@ -2167,10 +2187,11 @@ bool GUI_App::on_init_inner()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GUI_App::on_init_network()
|
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();
|
||||||
bool create_network_agent = false;
|
bool create_network_agent = false;
|
||||||
|
__retry:
|
||||||
if (!load_agent_dll) {
|
if (!load_agent_dll) {
|
||||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": on_init_network, load dll ok";
|
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": on_init_network, load dll ok";
|
||||||
if (check_networking_version()) {
|
if (check_networking_version()) {
|
||||||
|
@ -2185,6 +2206,13 @@ bool GUI_App::on_init_network()
|
||||||
else
|
else
|
||||||
create_network_agent = true;
|
create_network_agent = true;
|
||||||
} else {
|
} else {
|
||||||
|
if (try_backup) {
|
||||||
|
int result = Slic3r::NetworkAgent::unload_network_module();
|
||||||
|
BOOST_LOG_TRIVIAL(info) << "on_init_network, version mismatch, unload_network_module, result = " << result;
|
||||||
|
load_agent_dll = Slic3r::NetworkAgent::initialize_network_module(true);
|
||||||
|
try_backup = false;
|
||||||
|
goto __retry;
|
||||||
|
}
|
||||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": on_init_network, version dismatch, need upload network module";
|
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": on_init_network, version dismatch, need upload network module";
|
||||||
if (app_config->get("installed_networking") == "1") {
|
if (app_config->get("installed_networking") == "1") {
|
||||||
m_networking_need_update = true;
|
m_networking_need_update = true;
|
||||||
|
|
|
@ -518,7 +518,7 @@ public:
|
||||||
private:
|
private:
|
||||||
int updating_bambu_networking();
|
int updating_bambu_networking();
|
||||||
bool on_init_inner();
|
bool on_init_inner();
|
||||||
bool on_init_network();
|
bool on_init_network(bool try_backup = false);
|
||||||
void init_networking_callbacks();
|
void init_networking_callbacks();
|
||||||
void init_app_config();
|
void init_app_config();
|
||||||
//BBS set extra header for http request
|
//BBS set extra header for http request
|
||||||
|
|
|
@ -107,12 +107,16 @@ NetworkAgent::~NetworkAgent()
|
||||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", this %1%, network_agent=%2%, destroy_agent_ptr=%3%, ret %4%")%this %network_agent %destroy_agent_ptr %ret;
|
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", this %1%, network_agent=%2%, destroy_agent_ptr=%3%, ret %4%")%this %network_agent %destroy_agent_ptr %ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int NetworkAgent::initialize_network_module()
|
int NetworkAgent::initialize_network_module(bool using_backup)
|
||||||
{
|
{
|
||||||
//int ret = -1;
|
//int ret = -1;
|
||||||
std::string library;
|
std::string library;
|
||||||
auto plugin_folder = boost::filesystem::path(wxStandardPaths::Get().GetUserDataDir().ToUTF8().data()) / "plugins";
|
auto plugin_folder = boost::filesystem::path(wxStandardPaths::Get().GetUserDataDir().ToUTF8().data()) / "plugins";
|
||||||
|
|
||||||
|
if (using_backup) {
|
||||||
|
plugin_folder = plugin_folder/"backup";
|
||||||
|
}
|
||||||
|
|
||||||
//first load the library
|
//first load the library
|
||||||
#if defined(_MSC_VER) || defined(_WIN32)
|
#if defined(_MSC_VER) || defined(_WIN32)
|
||||||
library = plugin_folder.string() + "/" + std::string(BAMBU_NETWORK_LIBRARY) + ".dll";
|
library = plugin_folder.string() + "/" + std::string(BAMBU_NETWORK_LIBRARY) + ".dll";
|
||||||
|
|
|
@ -75,7 +75,7 @@ class NetworkAgent
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static int initialize_network_module();
|
static int initialize_network_module(bool using_backup = false);
|
||||||
static int unload_network_module();
|
static int unload_network_module();
|
||||||
#if defined(_MSC_VER) || defined(_WIN32)
|
#if defined(_MSC_VER) || defined(_WIN32)
|
||||||
static HMODULE get_bambu_source_entry();
|
static HMODULE get_bambu_source_entry();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue