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

Function savePackProfile

launcher/minecraft/PackProfile.cpp:152–182  ·  view source on GitHub ↗

Save the given component container data to a file

Source from the content-addressed store, hash-verified

150
151// Save the given component container data to a file
152static bool savePackProfile(const QString & filename, const ComponentContainer & container)
153{
154 QJsonObject obj;
155 obj.insert("formatVersion", currentComponentsFileVersion);
156 QJsonArray orderArray;
157 for(auto component: container)
158 {
159 orderArray.append(componentToJsonV1(component));
160 }
161 obj.insert("components", orderArray);
162 QSaveFile outFile(filename);
163 if (!outFile.open(QFile::WriteOnly))
164 {
165 qCritical() << "Couldn't open" << outFile.fileName()
166 << "for writing:" << outFile.errorString();
167 return false;
168 }
169 auto data = QJsonDocument(obj).toJson(QJsonDocument::Indented);
170 if(outFile.write(data) != data.size())
171 {
172 qCritical() << "Couldn't write all the data into" << outFile.fileName()
173 << "because:" << outFile.errorString();
174 return false;
175 }
176 if(!outFile.commit())
177 {
178 qCritical() << "Couldn't save" << outFile.fileName()
179 << "because:" << outFile.errorString();
180 }
181 return true;
182}
183
184// Read the given file into component containers
185static bool loadPackProfile(PackProfile * parent, const QString & filename, const QString & componentJsonPattern, ComponentContainer & container)

Callers 1

save_internalMethod · 0.85

Calls 7

componentToJsonV1Function · 0.85
insertMethod · 0.80
appendMethod · 0.80
openMethod · 0.80
toJsonMethod · 0.80
writeMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected