diff options
Diffstat (limited to 'src/libslic3r/AppConfig.cpp')
-rw-r--r-- | src/libslic3r/AppConfig.cpp | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/src/libslic3r/AppConfig.cpp b/src/libslic3r/AppConfig.cpp index ab636a03e..e64d19cfc 100644 --- a/src/libslic3r/AppConfig.cpp +++ b/src/libslic3r/AppConfig.cpp @@ -243,7 +243,7 @@ static bool verify_config_file_checksum(boost::nowide::ifstream &ifs) } #endif -std::string AppConfig::load() +std::string AppConfig::load(const std::string &path) { // 1) Read the complete config file into a boost::property_tree. namespace pt = boost::property_tree; @@ -252,11 +252,11 @@ std::string AppConfig::load() bool recovered = false; try { - ifs.open(AppConfig::loading_path()); + ifs.open(path); #ifdef WIN32 // Verify the checksum of the config file without taking just for debugging purpose. 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."; ifs.seekg(0, boost::nowide::ifstream::beg); @@ -266,32 +266,32 @@ std::string AppConfig::load() #ifdef WIN32 // The configuration file is corrupted, try replacing it with the backup configuration. 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)) { // 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); 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(); boost::filesystem::remove(backup_path); - } else if (std::string error_message; copy_file(backup_path, AppConfig::loading_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); + } 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%", path, backup_path, error_message); backup_ifs.close(); boost::filesystem::remove(backup_path); } 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 { - ifs.open(AppConfig::loading_path()); + ifs.open(path); pt::read_ini(ifs, tree); recovered = true; } 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 #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) { // Report the initial error of parsing PrusaSlicer.ini. // 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 ""; } +std::string AppConfig::load() +{ + return this->load(AppConfig::config_path()); +} + void AppConfig::save() { { |