Skip to content

Commit

Permalink
Automatically recover from corrupted config file
Browse files Browse the repository at this point in the history
  • Loading branch information
SoftFever committed Nov 9, 2023
1 parent df0a49a commit 22abe8c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/slic3r/GUI/GUI_App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2122,16 +2122,15 @@ void GUI_App::init_app_config()
app_config = new AppConfig();
//app_config = new AppConfig(is_editor() ? AppConfig::EAppMode::Editor : AppConfig::EAppMode::GCodeViewer);

m_config_corrupted = false;
// load settings
m_app_conf_exists = app_config->exists();
if (m_app_conf_exists) {
std::string error = app_config->load();
if (!error.empty()) {
// Error while parsing config file. We'll customize the error message and rethrow to be displayed.
throw Slic3r::RuntimeError(
_u8L("OrcaSlicer configuration file may be corrupted and is not abled to be parsed."
"Please delete the file and try again.") +
"\n\n" + app_config->config_path() + "\n\n" + error);
// Orca: if the config file is corrupted, we will show a error dialog and create a default config file.
m_config_corrupted = true;

}
// 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());
Expand Down Expand Up @@ -2748,13 +2747,21 @@ bool GUI_App::on_init_inner()

if (m_post_initialized && app_config->dirty())
app_config->save();

});

m_initialized = true;

flush_logs();

BOOST_LOG_TRIVIAL(info) << "finished the gui app init";
if (m_config_corrupted) {
m_config_corrupted = false;
show_error(nullptr,
_u8L(
"The OrcaSlicer configuration file may be corrupted and cannot be parsed.\nOrcaSlicer has attempted to recreate the "
"configuration file.\nPlease note, application settings will be lost, but printer profiles will not be affected."));
}
//BBS: delete splash screen
delete scrn;
return true;
Expand Down
1 change: 1 addition & 0 deletions src/slic3r/GUI/GUI_App.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,7 @@ class GUI_App : public wxApp
bool m_datadir_redefined { false };
std::string m_older_data_dir_path;
boost::optional<Semver> m_last_config_version;
bool m_config_corrupted { false };
};

DECLARE_APP(GUI_App)
Expand Down

0 comments on commit 22abe8c

Please sign in to comment.