Ported the AboutDialog to C++, thanks @alexrj for the work.

New "configuration" menu over the snapshots, user preferences etc.
This commit is contained in:
bubnikv 2018-04-09 17:03:37 +02:00
parent 601185f113
commit 32c4cddb91
15 changed files with 336 additions and 182 deletions

View file

@ -6,6 +6,8 @@
#include "../../libslic3r/libslic3r.h"
#include "../../libslic3r/Config.hpp"
#include "../../libslic3r/FileParserError.hpp"
#include "../../libslic3r/Utils.hpp"
namespace Slic3r {
namespace GUI {
@ -62,11 +64,12 @@ inline std::string unquote_version_comment(char *value, char *end, const std::st
return svalue;
}
size_t Index::load(const std::string &path)
size_t Index::load(const boost::filesystem::path &path)
{
m_configs.clear();
m_vendor = path.stem().string();
boost::nowide::ifstream ifs(path);
boost::nowide::ifstream ifs(path.string());
std::string line;
size_t idx_line = 0;
Version ver;
@ -96,7 +99,7 @@ size_t Index::load(const std::string &path)
if (semver)
throw file_parser_error("Key cannot be a semantic version", path, idx_line);
// Verify validity of the key / value pair.
std::string svalue = unquote_value(left_trim(++ value), end, path, idx_line);
std::string svalue = unquote_value(left_trim(++ value), end, path.string(), idx_line);
if (key == "min_sic3r_version" || key == "max_slic3r_version") {
if (! svalue.empty())
semver = Semver::parse(key);
@ -113,13 +116,24 @@ size_t Index::load(const std::string &path)
if (! semver)
throw file_parser_error("Invalid semantic version", path, idx_line);
ver.config_version = *semver;
ver.comment = (end <= key_end) ? "" : unquote_version_comment(value, end, path, idx_line);
ver.comment = (end <= key_end) ? "" : unquote_version_comment(value, end, path.string(), idx_line);
m_configs.emplace_back(ver);
}
// Sort the configs by their version.
std::sort(m_configs.begin(), m_configs.end(), [](const Version &v1, const Version &v2) { return v1.config_version < v2.config_version; });
return m_configs.size();
}
Index::const_iterator Index::find(const Semver &ver)
{
Version key;
key.config_version = ver;
auto it = std::lower_bound(m_configs.begin(), m_configs.end(), key,
[](const Version &v1, const Version &v2) { return v1.config_version < v2.config_version; });
return (it == m_configs.end() || it->config_version == ver) ? it : m_configs.end();
}
Index::const_iterator Index::recommended() const
{
int idx = -1;
@ -131,6 +145,31 @@ Index::const_iterator Index::recommended() const
return highest;
}
std::vector<Index> Index::load_db()
{
boost::filesystem::path data_dir = boost::filesystem::path(Slic3r::data_dir());
boost::filesystem::path vendor_dir = data_dir / "vendor";
std::vector<Index> index_db;
std::string errors_cummulative;
for (auto &dir_entry : boost::filesystem::directory_iterator(vendor_dir))
if (boost::filesystem::is_regular_file(dir_entry.status()) && boost::algorithm::iends_with(dir_entry.path().filename().string(), ".idx")) {
Index idx;
try {
idx.load(dir_entry.path());
} catch (const std::runtime_error &err) {
errors_cummulative += err.what();
errors_cummulative += "\n";
continue;
}
index_db.emplace_back(std::move(idx));
}
if (! errors_cummulative.empty())
throw std::runtime_error(errors_cummulative);
return index_db;
}
} // namespace Config
} // namespace GUI
} // namespace Slic3r