26{
27 po::options_description desc("OrcaSlicer System Cache Generator\nUsage");
28
29 desc.add_options()
30 ("help,h", "Show help")
31#ifdef __APPLE__
32 ("path,p", po::value<std::string>()->default_value("../../../../../../../resources/profiles"), "Path to profiles directory")
33#else
34 ("path,p", po::value<std::string>()->default_value("../../../resources/profiles"), "Path to profiles directory")
35#endif
36 ("log_level,l", po::value<int>()->default_value(2), "Log level (0=trace, 2=info, 4=error)")
37 ("vendor,v", po::value<std::string>()->default_value(""), "Vendor name. Optional; generate the cache for this vendor only (the Orca filament library is always included as the inheritance base). All vendors if not specified.");
38
39
40 po::variables_map vm;
41 try {
42 po::store(po::parse_command_line(argc, argv, desc), vm);
43 if (vm.count("help")) { std::cout << desc << "\n"; return 0; }
44 po::notify(vm);
45 } catch (const po::error& e) {
46 std::cerr << "Error: " << e.what() << "\n" << desc << "\n";
47 return 1;
48 }
49
50 const std::string profiles_path = vm["path"].as<std::string>();
51 const int log_level = vm["log_level"].as<int>();
52 const std::string vendor = vm["vendor"].as<std::string>();
53
54 if (!fs::exists(profiles_path) || !fs::is_directory(profiles_path)) {
55 std::cerr << "Error: '" << profiles_path << "' is not a valid directory\n";
56 return 1;
57 }
58
61 set_resources_dir(fs::path(profiles_path).parent_path().make_preferred().
string());
62
64 if (!fs::exists(user_dir))
65 fs::create_directories(user_dir);
66
68 app_config.
set(
"preset_folder",
"default");
69
70 auto preset_bundle = std::make_unique<PresetBundle>();
71 preset_bundle->set_is_validation_mode(true);
72 preset_bundle->set_default_suppressed(true);
73 preset_bundle->set_generate_vendor_caches(true);
74
75
76 preset_bundle->set_vendor_to_validate(vendor);
77
78 std::cout << "Loading system presets from: " << profiles_path
79 << (vendor.empty() ? "" : " (vendor: " + vendor + ")") << "\n";
80
81 try {
82
83
84 preset_bundle->load_presets(app_config, ForwardCompatibilitySubstitutionRule::EnableSilent);
85 } catch (const std::exception& ex) {
86 std::cerr << "Failed to load presets: " << ex.what() << "\n";
87 return 1;
88 }
89
90
91
92 if (!vendor.empty() && !fs::exists(fs::path(profiles_path) / (vendor + ".opc"))) {
93 std::cerr << "No cache was generated for vendor '" << vendor << "' under " << profiles_path
94 << " - check the vendor name.\n";
95 return 1;
96 }
97
98 size_t cache_count = 0;
99 for (auto& entry : fs::directory_iterator(profiles_path))
100 if (boost::iends_with(entry.path().string(), ".opc"))
101 ++ cache_count;
102 if (cache_count == 0) {
103 std::cerr << "No vendor cache files were generated under " << profiles_path << "\n";
104 return 1;
105 }
106 std::cout << "Generated " << cache_count << " vendor cache file(s) under " << profiles_path << "\n";
107 return 0;
108}
#define PRESET_USER_DIR
Definition Preset.hpp:32
Definition AppConfig.hpp:100
void set(const std::string §ion, const std::string &key, const std::string &value)
Definition AppConfig.hpp:167
void set_data_dir(const std::string &dir)
Definition utils.cpp:353
const std::string & data_dir()
Definition utils.cpp:365
void set_logging_level(unsigned int level)
Definition utils.cpp:171
void set_resources_dir(const std::string &dir)
Definition utils.cpp:291