diff --git a/src/slic3r/GUI/DeviceCore/DevConfigUtil.cpp b/src/slic3r/GUI/DeviceCore/DevConfigUtil.cpp index ef70218dd7..ccdfefd643 100644 --- a/src/slic3r/GUI/DeviceCore/DevConfigUtil.cpp +++ b/src/slic3r/GUI/DeviceCore/DevConfigUtil.cpp @@ -157,59 +157,66 @@ std::string DevPrinterConfigUtil::get_fan_text(const std::string& type_str, int std::map> DevPrinterConfigUtil::get_all_subseries(std::string type_str) { - std::vector m_files; std::map> subseries; #if !BBL_RELEASE_TO_PUBLIC BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": path= " << m_resource_file_path + "/printers/"; #endif - wxDir dir(m_resource_file_path + "/printers/"); - if (!dir.IsOpened()) { return subseries; } - - wxString filename; - bool hasFile = dir.GetFirst(&filename, "*.json", wxDIR_FILES); - while (hasFile) + try { - m_files.push_back(filename); - hasFile = dir.GetNext(&filename); - } - - for (wxString file : m_files) - { - std::string config_file = m_resource_file_path + "/printers/" + file.ToStdString(); - boost::nowide::ifstream json_file(config_file.c_str()); - - try + const auto& from_dir = m_resource_file_path + "/printers/"; + if (!boost::filesystem::exists(from_dir)) { - json jj; - if (json_file.is_open()) - { - json_file >> jj; - if (jj.contains("00.00.00.00")) - { - json const& printer = jj["00.00.00.00"]; - if (printer.contains("subseries")) - { - std::vector subs; + BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ": direction does not exist "; + return subseries; + } - std::string model_id = printer["model_id"].get(); - if (model_id == type_str || type_str.empty()) + for (const auto& entry : boost::filesystem::directory_iterator(from_dir)) + { + const boost::filesystem::path& file_path = entry.path(); + if (boost::filesystem::is_regular_file(file_path) && file_path.extension() == ".json") + { + try + { + json jj; + boost::nowide::ifstream json_file(file_path.string()); + if (json_file.is_open()) + { + json_file >> jj; + if (jj.contains("00.00.00.00")) { - for (auto res : printer["subseries"]) + json const& printer = jj["00.00.00.00"]; + if (printer.contains("subseries")) { - subs.emplace_back(res.get()); + std::vector subs; + std::string model_id = printer["model_id"].get(); + if (model_id == type_str || type_str.empty()) + { + for (auto res : printer["subseries"]) + { + subs.emplace_back(res.get()); + } + } + subseries.insert(make_pair(model_id, subs)); } } - subseries.insert(make_pair(model_id, subs)); } } + catch (...) + { + BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ": failed to load " << file_path.filename().string(); + } } } - catch (...) - { - BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ": failed to load " << file; - } + } + catch (const std::exception& e) + { + BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ": std::exception: " << e.what(); + } + catch (...) + { + BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ": unknown exception"; } #if !BBL_RELEASE_TO_PUBLIC