diff options
author | David Kocik <kocikdav@gmail.com> | 2022-01-21 15:40:50 +0300 |
---|---|---|
committer | David Kocik <kocikdav@gmail.com> | 2022-01-21 15:40:50 +0300 |
commit | 03be472a6d880eef673cd0f06fe634f3b6a0f15d (patch) | |
tree | 1048500b545372ea726a7ace0c5bcd8d7b348a60 | |
parent | fa9a0beec72f180a5226bb2f1203276dc7f37a64 (diff) |
Parsing of other PrusaSlicer.ini file.dk_parse_ini
Loading whole file as property tree a serching for version string in it. More robust solution that previous parsion of fist line.
-rw-r--r-- | src/slic3r/GUI/GUI_App.cpp | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index e60910908..d06625e11 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -845,18 +845,21 @@ bool GUI_App::init_opengl() // gets path to PrusaSlicer.ini, returns semver from first line comment static boost::optional<Semver> parse_semver_from_ini(std::string path) { - std::ifstream stream(path); - std::stringstream buffer; - buffer << stream.rdbuf(); - std::string body = buffer.str(); - size_t start = body.find("PrusaSlicer "); - if (start == std::string::npos) + // Parse Prusaslicer.ini at path into ptree + boost::property_tree::ptree tree; + boost::nowide::ifstream ifs(path); + try { + boost::property_tree::read_ini(ifs, tree); + } + catch (const boost::property_tree::ini_parser::ini_parser_error& err) { + BOOST_LOG_TRIVIAL(info) << format("Other configuration check: Failed to load PrusaSlicer.ini at \"%1%\"\nError: \"%2%\" at line %3%", path, err.message(), err.line()).c_str(); + return boost::none; + } + // its version string should be in the first layer under tag "version" + boost::property_tree::ptree::const_assoc_iterator it = tree.find("version"); + if (it == tree.not_found()) return boost::none; - body = body.substr(start + 12); - size_t end = body.find_first_of(" \n"); - if (end < body.size()) - body.resize(end); - return Semver::parse(body); + return Semver::parse(it->second.data()); } void GUI_App::init_app_config() |