Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/prusa3d/PrusaSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVojtech Bubnik <bubnikv@gmail.com>2021-12-15 12:30:15 +0300
committerVojtech Bubnik <bubnikv@gmail.com>2021-12-15 12:30:22 +0300
commitb95a83aec19e6366f8eb76dd1cd1a7b96c5437a7 (patch)
treef709b24a7634d575348005a7b6625a358b109d07
parent14cb4a131462fe38ba0d3b4f4d8912816daca8b0 (diff)
Bugfix: Loading of AppConfig from an alternate locations.
-rw-r--r--src/libslic3r/AppConfig.cpp27
-rw-r--r--src/libslic3r/AppConfig.hpp7
-rw-r--r--src/slic3r/GUI/GUI_App.cpp3
3 files changed, 19 insertions, 18 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()
{
{
diff --git a/src/libslic3r/AppConfig.hpp b/src/libslic3r/AppConfig.hpp
index 5d9f32ab7..cf69691de 100644
--- a/src/libslic3r/AppConfig.hpp
+++ b/src/libslic3r/AppConfig.hpp
@@ -38,6 +38,8 @@ public:
// Load the slic3r.ini from a user profile directory (or a datadir, if configured).
// return error string or empty strinf
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).
void save();
@@ -148,9 +150,6 @@ public:
// Does the config file exist?
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;
void set_recent_projects(const std::vector<std::string>& recent_projects);
@@ -199,8 +198,6 @@ private:
Semver m_orig_version;
// Whether the existing version is before system profiles & configuration updating
bool m_legacy_datadir;
-
- std::string m_loading_path;
};
} // namespace Slic3r
diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp
index 54807b35d..81488c4b0 100644
--- a/src/slic3r/GUI/GUI_App.cpp
+++ b/src/slic3r/GUI/GUI_App.cpp
@@ -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
m_init_app_config_from_older = true;
// 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();
+ std::string error = app_config->load((boost::filesystem::path(m_older_data_dir_path) / filename).string());
if (!error.empty()) {
// Error while parsing config file. We'll customize the error message and rethrow to be displayed.
if (is_editor()) {