From 31dc6491901c64b19fab1b6db1b3836d3da4f7ad Mon Sep 17 00:00:00 2001 From: bubnikv Date: Wed, 12 Dec 2018 19:02:18 +0100 Subject: [PATCH] Fix of https://github.com/prusa3d/Slic3r/issues/1298 Don't load preset files, if they are marked as hidden or system (Windows) --- src/slic3r/GUI/Preset.cpp | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/slic3r/GUI/Preset.cpp b/src/slic3r/GUI/Preset.cpp index 182181e70..4582e83ba 100644 --- a/src/slic3r/GUI/Preset.cpp +++ b/src/slic3r/GUI/Preset.cpp @@ -5,6 +5,12 @@ #include "BitmapCache.hpp" #include "I18N.hpp" +#ifdef _MSC_VER + #define WIN32_LEAN_AND_MEAN + #define NOMINMAX + #include +#endif /* _MSC_VER */ + #include #include #include @@ -13,6 +19,7 @@ #include #include +#include #include #include #include @@ -499,6 +506,16 @@ void PresetCollection::add_default_preset(const std::vector &keys, ++ m_num_default_presets; } +bool is_file_plain(const std::string &path) +{ +#ifdef _MSC_VER + DWORD attributes = GetFileAttributesW(boost::nowide::widen(path).c_str()); + return (attributes & (FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM)) == 0; +#else + return true; +#endif +} + // Load all presets found in dir_path. // Throws an exception on error. void PresetCollection::load_presets(const std::string &dir_path, const std::string &subdir) @@ -507,7 +524,10 @@ void PresetCollection::load_presets(const std::string &dir_path, const std::stri m_dir_path = dir.string(); std::string errors_cummulative; for (auto &dir_entry : boost::filesystem::directory_iterator(dir)) - if (boost::filesystem::is_regular_file(dir_entry.status()) && boost::algorithm::iends_with(dir_entry.path().filename().string(), ".ini")) { + if (boost::filesystem::is_regular_file(dir_entry.status()) && boost::algorithm::iends_with(dir_entry.path().filename().string(), ".ini") && + // Ignore system and hidden files, which may be created by the DropBox synchronisation process. + // https://github.com/prusa3d/Slic3r/issues/1298 + is_file_plain(dir_entry.path().string())) { std::string name = dir_entry.path().filename().string(); // Remove the .ini suffix. name.erase(name.size() - 4);