Save the given component container data to a file
| 150 | |
| 151 | // Save the given component container data to a file |
| 152 | static 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 |
| 185 | static bool loadPackProfile(PackProfile * parent, const QString & filename, const QString & componentJsonPattern, ComponentContainer & container) |
no test coverage detected