| 726 | } |
| 727 | |
| 728 | void InstanceList::loadGroupList() |
| 729 | { |
| 730 | qDebug() << "Will load group list now."; |
| 731 | |
| 732 | QString groupFileName = m_instDir + "/instgroups.json"; |
| 733 | |
| 734 | // if there's no group file, fail |
| 735 | if (!QFileInfo(groupFileName).exists()) |
| 736 | return; |
| 737 | |
| 738 | QByteArray jsonData; |
| 739 | try { |
| 740 | jsonData = FS::read(groupFileName); |
| 741 | } catch (const FS::FileSystemException& e) { |
| 742 | qCritical() << "Failed to read instance group file :" << e.cause(); |
| 743 | return; |
| 744 | } |
| 745 | |
| 746 | QJsonParseError error; |
| 747 | QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonData, &error); |
| 748 | |
| 749 | // if the json was bad, fail |
| 750 | if (error.error != QJsonParseError::NoError) { |
| 751 | qCritical() << QString("Failed to parse instance group file: %1 at offset %2") |
| 752 | .arg(error.errorString(), QString::number(error.offset)) |
| 753 | .toUtf8(); |
| 754 | return; |
| 755 | } |
| 756 | |
| 757 | // if the root of the json wasn't an object, fail |
| 758 | if (!jsonDoc.isObject()) { |
| 759 | qWarning() << "Invalid group file. Root entry should be an object."; |
| 760 | return; |
| 761 | } |
| 762 | |
| 763 | QJsonObject rootObj = jsonDoc.object(); |
| 764 | |
| 765 | // Make sure the format version matches, otherwise fail. |
| 766 | if (rootObj.value("formatVersion").toVariant().toInt() != GROUP_FILE_FORMAT_VERSION) |
| 767 | return; |
| 768 | |
| 769 | // Get the groups. if it's not an object, fail |
| 770 | if (!rootObj.value("groups").isObject()) { |
| 771 | qWarning() << "Invalid group list JSON: 'groups' should be an object."; |
| 772 | return; |
| 773 | } |
| 774 | |
| 775 | m_instanceGroupIndex.clear(); |
| 776 | m_groupNameCache.clear(); |
| 777 | |
| 778 | // Iterate through all the groups. |
| 779 | QJsonObject groupMapping = rootObj.value("groups").toObject(); |
| 780 | for (QJsonObject::iterator iter = groupMapping.begin(); iter != groupMapping.end(); iter++) { |
| 781 | QString groupName = iter.key(); |
| 782 | |
| 783 | if (iter.key().isEmpty()) { |
| 784 | qWarning() << "Redundant empty group found"; |
| 785 | continue; |
nothing calls this directly
no test coverage detected