MCPcopy Create free account
hub / github.com/PolyMC/PolyMC / ReadMCModTOML

Function ReadMCModTOML

launcher/minecraft/mod/tasks/LocalModParseTask.cpp:92–167  ·  view source on GitHub ↗

https://github.com/MinecraftForge/Documentation/blob/5ab4ba6cf9abc0ac4c0abd96ad187461aefd72af/docs/gettingstarted/structuring.md

Source from the content-addressed store, hash-verified

90
91// https://github.com/MinecraftForge/Documentation/blob/5ab4ba6cf9abc0ac4c0abd96ad187461aefd72af/docs/gettingstarted/structuring.md
92ModDetails ReadMCModTOML(QByteArray contents)
93{
94 ModDetails details;
95
96 toml::table tomlData;
97#if TOML_EXCEPTIONS
98 try {
99 tomlData = toml::parse(contents.toStdString());
100 } catch (const toml::parse_error& err) {
101 return {};
102 }
103#else
104 tomlData = toml::parse(contents.toStdString());
105 if (!tomlData) {
106 return {};
107 }
108#endif
109
110 // array defined by [[mods]]
111 auto tomlModsArr = tomlData["mods"].as_array();
112 if (!tomlModsArr) {
113 qWarning() << "Corrupted mods.toml? Couldn't find [[mods]] array!";
114 return {};
115 }
116
117 // we only really care about the first element, since multiple mods in one file is not supported by us at the moment
118 auto tomlModsTable0 = tomlModsArr->get(0);
119 if (!tomlModsTable0) {
120 qWarning() << "Corrupted mods.toml? [[mods]] didn't have an element at index 0!";
121 return {};
122 }
123 auto modsTable = tomlModsTable0->as_table();
124 if (!tomlModsTable0) {
125 qWarning() << "Corrupted mods.toml? [[mods]] was not a table!";
126 return {};
127 }
128
129 // mandatory properties - always in [[mods]]
130 if (auto modIdDatum = (*modsTable)["modId"].as_string()) {
131 details.mod_id = QString::fromStdString(modIdDatum->get());
132 }
133 if (auto versionDatum = (*modsTable)["version"].as_string()) {
134 details.version = QString::fromStdString(versionDatum->get());
135 }
136 if (auto displayNameDatum = (*modsTable)["displayName"].as_string()) {
137 details.name = QString::fromStdString(displayNameDatum->get());
138 }
139 if (auto descriptionDatum = (*modsTable)["description"].as_string()) {
140 details.description = QString::fromStdString(descriptionDatum->get());
141 }
142
143 // optional properties - can be in the root table or [[mods]]
144 QString authors = "";
145 if (auto authorsDatum = tomlData["authors"].as_string()) {
146 authors = QString::fromStdString(authorsDatum->get());
147 } else if (auto authorsDatum = (*modsTable)["authors"].as_string()) {
148 authors = QString::fromStdString(authorsDatum->get());
149 }

Callers 1

processAsZipMethod · 0.85

Calls 3

isEmptyMethod · 0.80
appendMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected