diff --git a/lib/Slic3r/GUI.pm b/lib/Slic3r/GUI.pm index 7157f7e92f..5176c9c915 100644 --- a/lib/Slic3r/GUI.pm +++ b/lib/Slic3r/GUI.pm @@ -100,16 +100,12 @@ sub OnInit { # Suppress the '- default -' presets. $self->{preset_bundle}->set_default_suppressed($self->{app_config}->get('no_defaults') ? 1 : 0); - eval { - $self->{preset_bundle}->load_presets(Slic3r::data_dir); - }; + eval { $self->{preset_bundle}->load_presets }; if ($@) { warn $@ . "\n"; show_error(undef, $@); } - eval { - $self->{preset_bundle}->load_selections($self->{app_config}); - }; + eval { $self->{preset_bundle}->load_selections($self->{app_config}) }; $run_wizard = 1 if $self->{preset_bundle}->has_defauls_only; # application frame diff --git a/lib/Slic3r/GUI/Tab.pm b/lib/Slic3r/GUI/Tab.pm index 907be7872b..30429e88bf 100644 --- a/lib/Slic3r/GUI/Tab.pm +++ b/lib/Slic3r/GUI/Tab.pm @@ -147,7 +147,7 @@ sub save_preset { return unless $dlg->ShowModal == wxID_OK; $name = $dlg->get_name; } - # Save the preset into Slic3r::data_dir/section_name/preset_name.ini + # Save the preset into Slic3r::data_dir/presets/section_name/preset_name.ini eval { $self->{presets}->save_current_preset($name); }; Slic3r::GUI::catch_error($self) and return; # Add the new item into the UI component, remove dirty flags and activate the saved item. diff --git a/xs/src/libslic3r/Utils.hpp b/xs/src/libslic3r/Utils.hpp index d988de8601..3afbc912f5 100644 --- a/xs/src/libslic3r/Utils.hpp +++ b/xs/src/libslic3r/Utils.hpp @@ -24,11 +24,6 @@ const std::string& resources_dir(); void set_data_dir(const std::string &path); // Return a full path to the GUI resource files. const std::string& data_dir(); -// Return a full path to a configuration file given its file name.. -std::string config_path(const std::string &file_name); -// Return a full path to a configuration file given the section and name. -// The suffix ".ini" will be added if it is missing in the name. -std::string config_path(const std::string §ion, const std::string &name); extern std::string encode_path(const char *src); extern std::string decode_path(const char *src); diff --git a/xs/src/libslic3r/utils.cpp b/xs/src/libslic3r/utils.cpp index 53efa466be..ee579161f4 100644 --- a/xs/src/libslic3r/utils.cpp +++ b/xs/src/libslic3r/utils.cpp @@ -113,19 +113,6 @@ const std::string& data_dir() return g_data_dir; } -std::string config_path(const std::string &file_name) -{ - auto file = (boost::filesystem::path(g_data_dir) / file_name).make_preferred(); - return file.string(); -} - -std::string config_path(const std::string §ion, const std::string &name) -{ - auto file_name = boost::algorithm::iends_with(name, ".ini") ? name : name + ".ini"; - auto file = (boost::filesystem::path(g_data_dir) / section / file_name).make_preferred(); - return file.string(); -} - } // namespace Slic3r #ifdef SLIC3R_HAS_BROKEN_CROAK diff --git a/xs/src/slic3r/GUI/PresetBundle.cpp b/xs/src/slic3r/GUI/PresetBundle.cpp index 1f872ffd6f..76fe3ae950 100644 --- a/xs/src/slic3r/GUI/PresetBundle.cpp +++ b/xs/src/slic3r/GUI/PresetBundle.cpp @@ -66,7 +66,12 @@ PresetBundle::~PresetBundle() void PresetBundle::setup_directories() { boost::filesystem::path data_dir = boost::filesystem::path(Slic3r::data_dir()); - std::initializer_list paths = { data_dir, data_dir / "print", data_dir / "filament", data_dir / "printer" }; + std::initializer_list paths = { + data_dir, + data_dir / "presets", + data_dir / "presets" / "print", + data_dir / "presets" / "filament", + data_dir / "presets" / "printer" }; for (const boost::filesystem::path &path : paths) { boost::filesystem::path subdir = path; subdir.make_preferred(); @@ -76,9 +81,10 @@ void PresetBundle::setup_directories() } } -void PresetBundle::load_presets(const std::string &dir_path) +void PresetBundle::load_presets() { std::string errors_cummulative; + const std::string dir_path = data_dir() + "/presets"; try { this->prints.load_presets(dir_path, "print"); } catch (const std::runtime_error &err) { @@ -465,8 +471,11 @@ size_t PresetBundle::load_configbundle(const std::string &path) for (auto &kvp : section.second) config.set_deserialize(kvp.first, kvp.second.data()); Preset::normalize(config); + // Decide a full path to this .ini file. + auto file_name = boost::algorithm::iends_with(preset_name, ".ini") ? preset_name : preset_name + ".ini"; + auto file_path = (boost::filesystem::path(data_dir()) / "presets" / presets->name() / file_name).make_preferred(); // Load the preset into the list of presets, save it to disk. - presets->load_preset(Slic3r::config_path(presets->name(), preset_name), preset_name, std::move(config), false).save(); + presets->load_preset(file_path.string(), preset_name, std::move(config), false).save(); ++ presets_loaded; } } diff --git a/xs/src/slic3r/GUI/PresetBundle.hpp b/xs/src/slic3r/GUI/PresetBundle.hpp index 451ec69c14..238e7c802b 100644 --- a/xs/src/slic3r/GUI/PresetBundle.hpp +++ b/xs/src/slic3r/GUI/PresetBundle.hpp @@ -17,8 +17,8 @@ public: void setup_directories(); - // Load ini files of all types (print, filament, printer) from the provided directory path. - void load_presets(const std::string &dir_path); + // Load ini files of all types (print, filament, printer) from Slic3r::data_dir() / presets. + void load_presets(); // Load selections (current print, current filaments, current printer) from config.ini // This is done just once on application start up. diff --git a/xs/xsp/GUI_Preset.xsp b/xs/xsp/GUI_Preset.xsp index a7fbdd07f9..d6af38d158 100644 --- a/xs/xsp/GUI_Preset.xsp +++ b/xs/xsp/GUI_Preset.xsp @@ -106,12 +106,13 @@ PresetCollection::arrayref() croak("Cannot create configuration directories:\n%s\n", e.what()); } %}; - void load_presets(const char *dir_path) + void load_presets() %code%{ try { - THIS->load_presets(dir_path); + THIS->load_presets(); } catch (std::exception& e) { - croak("Loading of Slic3r presets from %s failed.\n\n%s\n", dir_path, e.what()); + croak("Loading of Slic3r presets from %s failed.\n\n%s\n", + Slic3r::data_dir().c_str(), e.what()); } %}; void load_config_file(const char *path) diff --git a/xs/xsp/XS.xsp b/xs/xsp/XS.xsp index d59f826b71..b2f772834b 100644 --- a/xs/xsp/XS.xsp +++ b/xs/xsp/XS.xsp @@ -91,14 +91,6 @@ data_dir() RETVAL = const_cast(Slic3r::data_dir().c_str()); OUTPUT: RETVAL -std::string -config_path(section, name) - const char *section; - const char *name; - CODE: - RETVAL = Slic3r::config_path(section, name); - OUTPUT: RETVAL - std::string encode_path(src) const char *src;