Bugfix: Loading of AppConfig from an alternate locations.
This commit is contained in:
parent
14cb4a1314
commit
b95a83aec1
3 changed files with 19 additions and 18 deletions
src
|
@ -243,7 +243,7 @@ static bool verify_config_file_checksum(boost::nowide::ifstream &ifs)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
std::string AppConfig::load()
|
std::string AppConfig::load(const std::string &path)
|
||||||
{
|
{
|
||||||
// 1) Read the complete config file into a boost::property_tree.
|
// 1) Read the complete config file into a boost::property_tree.
|
||||||
namespace pt = boost::property_tree;
|
namespace pt = boost::property_tree;
|
||||||
|
@ -252,11 +252,11 @@ std::string AppConfig::load()
|
||||||
bool recovered = false;
|
bool recovered = false;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ifs.open(AppConfig::loading_path());
|
ifs.open(path);
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
// Verify the checksum of the config file without taking just for debugging purpose.
|
// Verify the checksum of the config file without taking just for debugging purpose.
|
||||||
if (!verify_config_file_checksum(ifs))
|
if (!verify_config_file_checksum(ifs))
|
||||||
BOOST_LOG_TRIVIAL(info) << "The configuration file " << AppConfig::loading_path() <<
|
BOOST_LOG_TRIVIAL(info) << "The configuration file " << path <<
|
||||||
" has a wrong MD5 checksum or the checksum is missing. This may indicate a file corruption or a harmless user edit.";
|
" has a wrong MD5 checksum or the checksum is missing. This may indicate a file corruption or a harmless user edit.";
|
||||||
|
|
||||||
ifs.seekg(0, boost::nowide::ifstream::beg);
|
ifs.seekg(0, boost::nowide::ifstream::beg);
|
||||||
|
@ -266,32 +266,32 @@ std::string AppConfig::load()
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
// The configuration file is corrupted, try replacing it with the backup configuration.
|
// The configuration file is corrupted, try replacing it with the backup configuration.
|
||||||
ifs.close();
|
ifs.close();
|
||||||
std::string backup_path = (boost::format("%1%.bak") % AppConfig::loading_path()).str();
|
std::string backup_path = (boost::format("%1%.bak") % path).str();
|
||||||
if (boost::filesystem::exists(backup_path)) {
|
if (boost::filesystem::exists(backup_path)) {
|
||||||
// Compute checksum of the configuration backup file and try to load configuration from it when the checksum is correct.
|
// Compute checksum of the configuration backup file and try to load configuration from it when the checksum is correct.
|
||||||
boost::nowide::ifstream backup_ifs(backup_path);
|
boost::nowide::ifstream backup_ifs(backup_path);
|
||||||
if (!verify_config_file_checksum(backup_ifs)) {
|
if (!verify_config_file_checksum(backup_ifs)) {
|
||||||
BOOST_LOG_TRIVIAL(error) << format("Both \"%1%\" and \"%2%\" are corrupted. It isn't possible to restore configuration from the backup.", AppConfig::loading_path(), backup_path);
|
BOOST_LOG_TRIVIAL(error) << format("Both \"%1%\" and \"%2%\" are corrupted. It isn't possible to restore configuration from the backup.", path, backup_path);
|
||||||
backup_ifs.close();
|
backup_ifs.close();
|
||||||
boost::filesystem::remove(backup_path);
|
boost::filesystem::remove(backup_path);
|
||||||
} else if (std::string error_message; copy_file(backup_path, AppConfig::loading_path(), error_message, false) != SUCCESS) {
|
} else if (std::string error_message; copy_file(backup_path, path, error_message, false) != SUCCESS) {
|
||||||
BOOST_LOG_TRIVIAL(error) << format("Configuration file \"%1%\" is corrupted. Failed to restore from backup \"%2%\": %3%", AppConfig::loading_path(), backup_path, error_message);
|
BOOST_LOG_TRIVIAL(error) << format("Configuration file \"%1%\" is corrupted. Failed to restore from backup \"%2%\": %3%", path, backup_path, error_message);
|
||||||
backup_ifs.close();
|
backup_ifs.close();
|
||||||
boost::filesystem::remove(backup_path);
|
boost::filesystem::remove(backup_path);
|
||||||
} else {
|
} else {
|
||||||
BOOST_LOG_TRIVIAL(info) << format("Configuration file \"%1%\" was corrupted. It has been succesfully restored from the backup \"%2%\".", AppConfig::loading_path(), backup_path);
|
BOOST_LOG_TRIVIAL(info) << format("Configuration file \"%1%\" was corrupted. It has been succesfully restored from the backup \"%2%\".", path, backup_path);
|
||||||
// Try parse configuration file after restore from backup.
|
// Try parse configuration file after restore from backup.
|
||||||
try {
|
try {
|
||||||
ifs.open(AppConfig::loading_path());
|
ifs.open(path);
|
||||||
pt::read_ini(ifs, tree);
|
pt::read_ini(ifs, tree);
|
||||||
recovered = true;
|
recovered = true;
|
||||||
} catch (pt::ptree_error& ex) {
|
} catch (pt::ptree_error& ex) {
|
||||||
BOOST_LOG_TRIVIAL(info) << format("Failed to parse configuration file \"%1%\" after it has been restored from backup: %2%", AppConfig::loading_path(), ex.what());
|
BOOST_LOG_TRIVIAL(info) << format("Failed to parse configuration file \"%1%\" after it has been restored from backup: %2%", path, ex.what());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
#endif // WIN32
|
#endif // WIN32
|
||||||
BOOST_LOG_TRIVIAL(info) << format("Failed to parse configuration file \"%1%\": %2%", AppConfig::loading_path(), ex.what());
|
BOOST_LOG_TRIVIAL(info) << format("Failed to parse configuration file \"%1%\": %2%", path, ex.what());
|
||||||
if (! recovered) {
|
if (! recovered) {
|
||||||
// Report the initial error of parsing PrusaSlicer.ini.
|
// Report the initial error of parsing PrusaSlicer.ini.
|
||||||
// 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.
|
||||||
|
@ -367,6 +367,11 @@ std::string AppConfig::load()
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string AppConfig::load()
|
||||||
|
{
|
||||||
|
return this->load(AppConfig::config_path());
|
||||||
|
}
|
||||||
|
|
||||||
void AppConfig::save()
|
void AppConfig::save()
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
|
|
|
@ -38,6 +38,8 @@ public:
|
||||||
// Load the slic3r.ini from a user profile directory (or a datadir, if configured).
|
// Load the slic3r.ini from a user profile directory (or a datadir, if configured).
|
||||||
// return error string or empty strinf
|
// return error string or empty strinf
|
||||||
std::string load();
|
std::string load();
|
||||||
|
// Load from an explicit path.
|
||||||
|
std::string load(const std::string &path);
|
||||||
// Store the slic3r.ini into a user profile directory (or a datadir, if configured).
|
// Store the slic3r.ini into a user profile directory (or a datadir, if configured).
|
||||||
void save();
|
void save();
|
||||||
|
|
||||||
|
@ -148,9 +150,6 @@ public:
|
||||||
// Does the config file exist?
|
// Does the config file exist?
|
||||||
bool exists();
|
bool exists();
|
||||||
|
|
||||||
void set_loading_path(const std::string& path) { m_loading_path = path; }
|
|
||||||
std::string loading_path() { return (m_loading_path.empty() ? config_path() : m_loading_path); }
|
|
||||||
|
|
||||||
std::vector<std::string> get_recent_projects() const;
|
std::vector<std::string> get_recent_projects() const;
|
||||||
void set_recent_projects(const std::vector<std::string>& recent_projects);
|
void set_recent_projects(const std::vector<std::string>& recent_projects);
|
||||||
|
|
||||||
|
@ -199,8 +198,6 @@ private:
|
||||||
Semver m_orig_version;
|
Semver m_orig_version;
|
||||||
// Whether the existing version is before system profiles & configuration updating
|
// Whether the existing version is before system profiles & configuration updating
|
||||||
bool m_legacy_datadir;
|
bool m_legacy_datadir;
|
||||||
|
|
||||||
std::string m_loading_path;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Slic3r
|
} // namespace Slic3r
|
||||||
|
|
|
@ -992,8 +992,7 @@ bool GUI_App::check_older_app_config(Semver current_version, bool backup)
|
||||||
// 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 m_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
|
||||||
app_config->set_loading_path((boost::filesystem::path(m_older_data_dir_path) / filename).string());
|
std::string error = app_config->load((boost::filesystem::path(m_older_data_dir_path) / filename).string());
|
||||||
std::string error = app_config->load();
|
|
||||||
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()) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue