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

Function loadPackProfile

launcher/minecraft/PackProfile.cpp:185–236  ·  view source on GitHub ↗

Read the given file into component containers

Source from the content-addressed store, hash-verified

183
184// Read the given file into component containers
185static bool loadPackProfile(PackProfile * parent, const QString & filename, const QString & componentJsonPattern, ComponentContainer & container)
186{
187 QFile componentsFile(filename);
188 if (!componentsFile.exists())
189 {
190 qWarning() << "Components file doesn't exist. This should never happen.";
191 return false;
192 }
193 if (!componentsFile.open(QFile::ReadOnly))
194 {
195 qCritical() << "Couldn't open" << componentsFile.fileName()
196 << " for reading:" << componentsFile.errorString();
197 qWarning() << "Ignoring overriden order";
198 return false;
199 }
200
201 // and it's valid JSON
202 QJsonParseError error;
203 QJsonDocument doc = QJsonDocument::fromJson(componentsFile.readAll(), &error);
204 if (error.error != QJsonParseError::NoError)
205 {
206 qCritical() << "Couldn't parse" << componentsFile.fileName() << ":" << error.errorString();
207 qWarning() << "Ignoring overriden order";
208 return false;
209 }
210
211 // and then read it and process it if all above is true.
212 try
213 {
214 auto obj = Json::requireObject(doc);
215 // check order file version.
216 auto version = Json::requireInteger(obj.value("formatVersion"));
217 if (version != currentComponentsFileVersion)
218 {
219 throw JSONValidationError(QObject::tr("Invalid component file version, expected %1")
220 .arg(currentComponentsFileVersion));
221 }
222 auto orderArray = Json::requireArray(obj.value("components"));
223 for(auto item: orderArray)
224 {
225 auto obj = Json::requireObject(item, "Component must be an object.");
226 container.append(componentFromJsonV1(parent, componentJsonPattern, obj));
227 }
228 }
229 catch (const JSONValidationError &err)
230 {
231 qCritical() << "Couldn't parse" << componentsFile.fileName() << ": bad file format";
232 container.clear();
233 return false;
234 }
235 return true;
236}
237
238// END: component file format
239

Callers 2

loadComponentsMethod · 0.85
loadMethod · 0.85

Calls 8

fromJsonFunction · 0.85
requireObjectFunction · 0.85
requireArrayFunction · 0.85
componentFromJsonV1Function · 0.85
existsMethod · 0.80
openMethod · 0.80
appendMethod · 0.80
clearMethod · 0.45

Tested by

no test coverage detected