Some improvements to copying of newer configuration to current folder:

1) Less context is kept in GUI_App.
2) Copying is not being done if loading current PrusaSlicer.ini fails
3) AppConfig (PrusaSlicer.ini) is saved first after the newer configuration is installed.
This commit is contained in:
Vojtech Bubnik 2021-12-15 11:09:27 +01:00
parent 3ec78c4ccf
commit 87880022fc
2 changed files with 33 additions and 36 deletions

View file

@ -909,17 +909,18 @@ void GUI_App::init_app_config()
"\n\n" + app_config->config_path() + "\n\n" + error); "\n\n" + app_config->config_path() + "\n\n" + error);
} }
} }
// Save orig_version here, so its empty if no app_config existed before this run.
m_last_config_version = app_config->orig_version();//parse_semver_from_ini(app_config->config_path());
} }
} }
// returns true if found newer version and user agreed to use it // returns old config path to copy from if such exists,
bool GUI_App::check_older_app_config(Semver current_version, bool backup) // returns an empty string if such config path does not exists or if it cannot be loaded.
std::string GUI_App::check_older_app_config(Semver current_version, bool backup)
{ {
std::string older_data_dir_path;
// If the config folder is redefined - do not check // If the config folder is redefined - do not check
if (m_datadir_redefined) if (m_datadir_redefined)
return false; return {};
// find other version app config (alpha / beta / release) // find other version app config (alpha / beta / release)
std::string config_path = app_config->config_path(); std::string config_path = app_config->config_path();
@ -940,13 +941,13 @@ bool GUI_App::check_older_app_config(Semver current_version, bool backup)
boost::optional<Semver>other_semver = parse_semver_from_ini(candidate.string()); boost::optional<Semver>other_semver = parse_semver_from_ini(candidate.string());
if (other_semver && *other_semver > last_semver) { if (other_semver && *other_semver > last_semver) {
last_semver = *other_semver; last_semver = *other_semver;
m_older_data_dir_path = candidate.parent_path().string(); older_data_dir_path = candidate.parent_path().string();
} }
} }
} }
if (m_older_data_dir_path.empty()) if (older_data_dir_path.empty())
return false; return {};
BOOST_LOG_TRIVIAL(info) << "last app config file used: " << m_older_data_dir_path; BOOST_LOG_TRIVIAL(info) << "last app config file used: " << older_data_dir_path;
// ask about using older data folder // ask about using older data folder
InfoDialog msg(nullptr InfoDialog msg(nullptr
@ -959,13 +960,13 @@ bool GUI_App::check_older_app_config(Semver current_version, bool backup)
"\n\nShall the newer configuration be imported?" "\n\nShall the newer configuration be imported?"
"\nIf so, your active configuration will be backed up before importing the new configuration." "\nIf so, your active configuration will be backed up before importing the new configuration."
) )
, SLIC3R_APP_NAME, current_version.to_string(), m_older_data_dir_path, last_semver.to_string()) , SLIC3R_APP_NAME, current_version.to_string(), older_data_dir_path, last_semver.to_string())
: format_wxstr(_L( : format_wxstr(_L(
"An existing configuration was found in <b>%3%</b>" "An existing configuration was found in <b>%3%</b>"
"\ncreated by <b>%1% %2%</b>." "\ncreated by <b>%1% %2%</b>."
"\n\nShall this configuration be imported?" "\n\nShall this configuration be imported?"
) )
, SLIC3R_APP_NAME, last_semver.to_string(), m_older_data_dir_path) , SLIC3R_APP_NAME, last_semver.to_string(), older_data_dir_path)
, true, wxYES_NO); , true, wxYES_NO);
if (backup) { if (backup) {
@ -989,10 +990,10 @@ bool GUI_App::check_older_app_config(Semver current_version, bool backup)
BOOST_LOG_TRIVIAL(error) << "Failed to take congiguration snapshot: "; BOOST_LOG_TRIVIAL(error) << "Failed to take congiguration snapshot: ";
} }
// This will tell later (when config folder structure is sure to exists) to copy files from m_older_data_dir_path // This will tell later (when config folder structure is sure to exists) to copy files from older_data_dir_path
m_init_app_config_from_older = true; m_init_app_config_from_older = true;
// load app config from older file // load app config from older file
std::string error = app_config->load((boost::filesystem::path(m_older_data_dir_path) / filename).string()); std::string error = app_config->load((boost::filesystem::path(older_data_dir_path) / filename).string());
if (!error.empty()) { if (!error.empty()) {
// Error while parsing config file. We'll customize the error message and rethrow to be displayed. // Error while parsing config file. We'll customize the error message and rethrow to be displayed.
if (is_editor()) { if (is_editor()) {
@ -1011,14 +1012,9 @@ bool GUI_App::check_older_app_config(Semver current_version, bool backup)
if (!snapshot_id.empty()) if (!snapshot_id.empty())
app_config->set("on_snapshot", snapshot_id); app_config->set("on_snapshot", snapshot_id);
m_app_conf_exists = true; m_app_conf_exists = true;
return true; return older_data_dir_path;
} }
return false; return {};
}
void GUI_App::copy_older_config()
{
preset_bundle->copy_files(m_older_data_dir_path);
} }
void GUI_App::init_single_instance_checker(const std::string &name, const std::string &path) void GUI_App::init_single_instance_checker(const std::string &name, const std::string &path)
@ -1117,16 +1113,16 @@ bool GUI_App::on_init_inner()
init_label_colours(); init_label_colours();
init_fonts(); init_fonts();
if (m_last_config_version) { std::string older_data_dir_path;
if (*m_last_config_version < *Semver::parse(SLIC3R_VERSION)) if (m_app_conf_exists) {
check_older_app_config(*m_last_config_version, true); if (app_config->orig_version() && *app_config->orig_version() < *Semver::parse(SLIC3R_VERSION))
// Only copying configuration if it was saved with a newer slicer than the one currently running.
older_data_dir_path = check_older_app_config(*app_config->orig_version(), true);
} else { } else {
check_older_app_config(Semver(), false); // No AppConfig exists, fresh install. Always try to copy from an alternate location, don't make backup of the current configuration.
older_data_dir_path = check_older_app_config(Semver(), false);
} }
app_config->set("version", SLIC3R_VERSION);
app_config->save();
SplashScreen* scrn = nullptr; SplashScreen* scrn = nullptr;
if (app_config->get("show_splash_screen") == "1") { if (app_config->get("show_splash_screen") == "1") {
// make a bitmap with dark grey banner on the left side // make a bitmap with dark grey banner on the left side
@ -1155,10 +1151,13 @@ bool GUI_App::on_init_inner()
// just checking for existence of Slic3r::data_dir is not enough : it may be an empty directory // just checking for existence of Slic3r::data_dir is not enough : it may be an empty directory
// supplied as argument to --datadir; in that case we should still run the wizard // supplied as argument to --datadir; in that case we should still run the wizard
preset_bundle->setup_directories(); preset_bundle->setup_directories();
if (m_init_app_config_from_older) if (! older_data_dir_path.empty())
copy_older_config(); preset_bundle->copy_files(older_data_dir_path);
// Save PrusaSlicer.ini after possibly copying the config from the alternate location and after all the configs from the alternate location were copied.
app_config->set("version", SLIC3R_VERSION);
app_config->save();
if (is_editor()) { if (is_editor()) {
#ifdef __WXMSW__ #ifdef __WXMSW__

View file

@ -341,8 +341,9 @@ public:
private: private:
bool on_init_inner(); bool on_init_inner();
void init_app_config(); void init_app_config();
bool check_older_app_config(Semver current_version, bool backup); // returns old config path to copy from if such exists,
void copy_older_config(); // returns an empty string if such config path does not exists or if it cannot be loaded.
std::string check_older_app_config(Semver current_version, bool backup);
void window_pos_save(wxTopLevelWindow* window, const std::string &name); void window_pos_save(wxTopLevelWindow* window, const std::string &name);
void window_pos_restore(wxTopLevelWindow* window, const std::string &name, bool default_maximized = false); void window_pos_restore(wxTopLevelWindow* window, const std::string &name, bool default_maximized = false);
void window_pos_sanitize(wxTopLevelWindow* window); void window_pos_sanitize(wxTopLevelWindow* window);
@ -351,10 +352,7 @@ private:
bool config_wizard_startup(); bool config_wizard_startup();
void check_updates(const bool verbose); void check_updates(const bool verbose);
bool m_init_app_config_from_older { false }; bool m_datadir_redefined { false };
bool m_datadir_redefined { false };
std::string m_older_data_dir_path;
boost::optional<Semver> m_last_config_version;
}; };
DECLARE_APP(GUI_App) DECLARE_APP(GUI_App)