MCPcopy Create free account
hub / github.com/MultiMC/Launcher / loadPackProfile

Function loadPackProfile

launcher/minecraft/PackProfile.cpp:157–208  ·  view source on GitHub ↗

Read the given file into component containers

Source from the content-addressed store, hash-verified

155
156// Read the given file into component containers
157static bool loadPackProfile(PackProfile * parent, const QString & filename, const QString & componentJsonPattern, ComponentContainer & container)
158{
159 QFile componentsFile(filename);
160 if (!componentsFile.exists())
161 {
162 qWarning() << "Components file doesn't exist. This should never happen.";
163 return false;
164 }
165 if (!componentsFile.open(QFile::ReadOnly))
166 {
167 qCritical() << "Couldn't open" << componentsFile.fileName()
168 << " for reading:" << componentsFile.errorString();
169 qWarning() << "Ignoring overriden order";
170 return false;
171 }
172
173 // and it's valid JSON
174 QJsonParseError error;
175 QJsonDocument doc = QJsonDocument::fromJson(componentsFile.readAll(), &error);
176 if (error.error != QJsonParseError::NoError)
177 {
178 qCritical() << "Couldn't parse" << componentsFile.fileName() << ":" << error.errorString();
179 qWarning() << "Ignoring overriden order";
180 return false;
181 }
182
183 // and then read it and process it if all above is true.
184 try
185 {
186 auto obj = Json::requireObject(doc);
187 // check order file version.
188 auto version = Json::requireValueInteger(obj.value("formatVersion"));
189 if (version != currentComponentsFileVersion)
190 {
191 throw JSONValidationError(QObject::tr("Invalid component file version, expected %1")
192 .arg(currentComponentsFileVersion));
193 }
194 auto orderArray = Json::requireValueArray(obj.value("components"));
195 for(auto item: orderArray)
196 {
197 auto obj = Json::requireValueObject(item, "Component must be an object.");
198 container.append(componentFromJsonV1(parent, componentJsonPattern, obj));
199 }
200 }
201 catch (const JSONValidationError &err)
202 {
203 qCritical() << "Couldn't parse" << componentsFile.fileName() << ": bad file format";
204 container.clear();
205 return false;
206 }
207 return true;
208}
209
210// END: component file format
211

Callers 2

loadComponentsMethod · 0.85
loadMethod · 0.85

Calls 7

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

Tested by

no test coverage detected