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

github.com/supermerill/SuperSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbubnikv <bubnikv@gmail.com>2020-03-07 18:31:14 +0300
committerbubnikv <bubnikv@gmail.com>2020-03-07 18:31:14 +0300
commit76fecc91a5465d1167a1e105876f473e2bf449dd (patch)
tree943a481a65e492585b4056fce91d319a7cf6048c /src/slic3r/GUI
parent93f2be7ac426c5acbaf7b30c1149d222b02ff58a (diff)
Improved error reporting and error handling when loading
vendor config bundles into installation wizard.
Diffstat (limited to 'src/slic3r/GUI')
-rw-r--r--src/slic3r/GUI/ConfigWizard.cpp39
-rw-r--r--src/slic3r/GUI/ConfigWizard_private.hpp11
-rw-r--r--src/slic3r/GUI/PresetBundle.cpp12
3 files changed, 44 insertions, 18 deletions
diff --git a/src/slic3r/GUI/ConfigWizard.cpp b/src/slic3r/GUI/ConfigWizard.cpp
index 9d241b0da..e66922630 100644
--- a/src/slic3r/GUI/ConfigWizard.cpp
+++ b/src/slic3r/GUI/ConfigWizard.cpp
@@ -42,16 +42,27 @@ using Config::SnapshotDB;
// Configuration data structures extensions needed for the wizard
-Bundle::Bundle(fs::path source_path, bool is_in_resources, bool is_prusa_bundle)
- : preset_bundle(new PresetBundle)
- , vendor_profile(nullptr)
- , is_in_resources(is_in_resources)
- , is_prusa_bundle(is_prusa_bundle)
+bool Bundle::load(fs::path source_path, bool ais_in_resources, bool ais_prusa_bundle)
{
- preset_bundle->load_configbundle(source_path.string(), PresetBundle::LOAD_CFGBNDLE_SYSTEM);
+ this->preset_bundle = std::make_unique<PresetBundle>();
+ this->is_in_resources = ais_in_resources;
+ this->is_prusa_bundle = ais_prusa_bundle;
+
+ std::string path_string = source_path.string();
+ size_t presets_loaded = preset_bundle->load_configbundle(path_string, PresetBundle::LOAD_CFGBNDLE_SYSTEM);
auto first_vendor = preset_bundle->vendors.begin();
- wxCHECK_RET(first_vendor != preset_bundle->vendors.end(), "Failed to load preset bundle");
- vendor_profile = &first_vendor->second;
+ if (first_vendor == preset_bundle->vendors.end()) {
+ BOOST_LOG_TRIVIAL(error) << boost::format("Vendor bundle: `%1%`: No vendor information defined, cannot install.") % path_string;
+ return false;
+ }
+ if (presets_loaded == 0) {
+ BOOST_LOG_TRIVIAL(error) << boost::format("Vendor bundle: `%1%`: No profile loaded.") % path_string;
+ return false;
+ }
+
+ BOOST_LOG_TRIVIAL(trace) << boost::format("Vendor bundle: `%1%`: %2% profiles loaded.") % path_string % presets_loaded;
+ this->vendor_profile = &first_vendor->second;
+ return true;
}
Bundle::Bundle(Bundle &&other)
@@ -76,8 +87,11 @@ BundleMap BundleMap::load()
prusa_bundle_path = (rsrc_vendor_dir / PresetBundle::PRUSA_BUNDLE).replace_extension(".ini");
prusa_bundle_rsrc = true;
}
- Bundle prusa_bundle(std::move(prusa_bundle_path), prusa_bundle_rsrc, true);
- res.emplace(PresetBundle::PRUSA_BUNDLE, std::move(prusa_bundle));
+ {
+ Bundle prusa_bundle;
+ if (prusa_bundle.load(std::move(prusa_bundle_path), prusa_bundle_rsrc, true))
+ res.emplace(PresetBundle::PRUSA_BUNDLE, std::move(prusa_bundle));
+ }
// Load the other bundles in the datadir/vendor directory
// and then additionally from resources/profiles.
@@ -90,8 +104,9 @@ BundleMap BundleMap::load()
// Don't load this bundle if we've already loaded it.
if (res.find(id) != res.end()) { continue; }
- Bundle bundle(dir_entry.path(), is_in_resources);
- res.emplace(std::move(id), std::move(bundle));
+ Bundle bundle;
+ if (bundle.load(dir_entry.path(), is_in_resources))
+ res.emplace(std::move(id), std::move(bundle));
}
}
diff --git a/src/slic3r/GUI/ConfigWizard_private.hpp b/src/slic3r/GUI/ConfigWizard_private.hpp
index 1d4b64221..64081153d 100644
--- a/src/slic3r/GUI/ConfigWizard_private.hpp
+++ b/src/slic3r/GUI/ConfigWizard_private.hpp
@@ -100,13 +100,16 @@ struct Materials
struct Bundle
{
std::unique_ptr<PresetBundle> preset_bundle;
- VendorProfile *vendor_profile;
- const bool is_in_resources;
- const bool is_prusa_bundle;
+ VendorProfile *vendor_profile { nullptr };
+ bool is_in_resources { false };
+ bool is_prusa_bundle { false };
- Bundle(fs::path source_path, bool is_in_resources, bool is_prusa_bundle = false);
+ Bundle() = default;
Bundle(Bundle &&other);
+ // Returns false if not loaded. Reason for that is logged as boost::log error.
+ bool load(fs::path source_path, bool is_in_resources, bool is_prusa_bundle = false);
+
const std::string& vendor_id() const { return vendor_profile->id; }
};
diff --git a/src/slic3r/GUI/PresetBundle.cpp b/src/slic3r/GUI/PresetBundle.cpp
index 3aa947f1b..2b5c062e6 100644
--- a/src/slic3r/GUI/PresetBundle.cpp
+++ b/src/slic3r/GUI/PresetBundle.cpp
@@ -703,7 +703,10 @@ void PresetBundle::load_config_file(const std::string &path)
boost::nowide::ifstream ifs(path);
boost::property_tree::read_ini(ifs, tree);
} catch (const std::ifstream::failure &err) {
- throw std::runtime_error(std::string("The config file cannot be loaded: ") + path + "\n\tReason: " + err.what());
+ throw std::runtime_error(std::string("The Config Bundle cannot be loaded: ") + path + "\n\tReason: " + err.what());
+ } catch (const boost::property_tree::file_parser_error &err) {
+ throw std::runtime_error((boost::format("Failed loading the Config Bundle \"%1%\": %2% at line %3%")
+ % err.filename() % err.message() % err.line()).str());
} catch (const std::runtime_error &err) {
throw std::runtime_error(std::string("Failed loading the preset file: ") + path + "\n\tReason: " + err.what());
}
@@ -1109,8 +1112,13 @@ size_t PresetBundle::load_configbundle(const std::string &path, unsigned int fla
const VendorProfile *vendor_profile = nullptr;
if (flags & (LOAD_CFGBNDLE_SYSTEM | LOAD_CFGBUNDLE_VENDOR_ONLY)) {
auto vp = VendorProfile::from_ini(tree, path);
- if (vp.num_variants() == 0)
+ if (vp.models.size() == 0) {
+ BOOST_LOG_TRIVIAL(error) << boost::format("Vendor bundle: `%1%`: No printer model defined.") % path;
return 0;
+ } else if (vp.num_variants() == 0) {
+ BOOST_LOG_TRIVIAL(error) << boost::format("Vendor bundle: `%1%`: No printer variant defined") % path;
+ return 0;
+ }
vendor_profile = &this->vendors.insert({vp.id, vp}).first->second;
}