MCPcopy Create free account
hub / github.com/N64Recomp/N64Recomp / parse_mod_config_manifest

Function parse_mod_config_manifest

RecompModTool/main.cpp:230–375  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

228}
229
230ModManifest parse_mod_config_manifest(const std::filesystem::path& basedir, const toml::table& manifest_table) {
231 ModManifest ret;
232
233 // Mod ID
234 ret.mod_id = read_toml_value<std::string_view>(manifest_table, "id", true);
235 if (!N64Recomp::validate_mod_id(ret.mod_id)) {
236 throw toml::parse_error("Invalid mod id", manifest_table["id"].node()->source());
237 }
238
239 // Mod version
240 ret.version_string = read_toml_value<std::string_view>(manifest_table, "version", true);
241 bool version_has_label;
242 if (!validate_version_string(ret.version_string, version_has_label)) {
243 throw toml::parse_error("Invalid mod version", manifest_table["version"].node()->source());
244 }
245
246 // Display name
247 ret.display_name = read_toml_value<std::string_view>(manifest_table, "display_name", true);
248
249 // Description (optional)
250 ret.description = read_toml_value<std::string_view>(manifest_table, "description", false);
251
252 // Short description (optional)
253 ret.short_description = read_toml_value<std::string_view>(manifest_table, "short_description", false);
254
255 // Authors
256 const toml::array& authors_array = read_toml_array(manifest_table, "authors", true);
257 authors_array.for_each([&ret](auto&& el) {
258 if constexpr (toml::is_string<decltype(el)>) {
259 ret.authors.emplace_back(el.template ref<std::string>());
260 }
261 else {
262 throw toml::parse_error("Invalid type for author entry", el.source());
263 }
264 });
265
266 // Game ID
267 ret.game_id = read_toml_value<std::string_view>(manifest_table, "game_id", true);
268
269 // Minimum recomp version
270 ret.minimum_recomp_version = read_toml_value<std::string_view>(manifest_table, "minimum_recomp_version", true);
271 bool minimum_recomp_version_has_label;
272 if (!validate_version_string(ret.minimum_recomp_version, minimum_recomp_version_has_label)) {
273 throw toml::parse_error("Invalid minimum recomp version", manifest_table["minimum_recomp_version"].node()->source());
274 }
275 if (minimum_recomp_version_has_label) {
276 throw toml::parse_error("Minimum recomp version may not have a label", manifest_table["minimum_recomp_version"].node()->source());
277 }
278
279 // Native libraries (optional)
280 const toml::array& native_libraries = read_toml_array(manifest_table, "native_libraries", false);
281 if (!native_libraries.empty()) {
282 native_libraries.for_each([&ret](const auto& el) {
283 if constexpr (toml::is_table<decltype(el)>) {
284 const toml::table& el_table = *el.as_table();
285 std::string_view library_name = read_toml_value<std::string_view>(el_table, "name", true);
286 const toml::array funcs_array = read_toml_array(el_table, "funcs", true);
287 std::vector<std::string> cur_funcs{};

Callers 1

parse_mod_configFunction · 0.85

Calls 4

validate_mod_idFunction · 0.85
validate_version_stringFunction · 0.85
validate_config_optionFunction · 0.85

Tested by

no test coverage detected