| 631 | } |
| 632 | |
| 633 | void InstanceList::loadGroupList() |
| 634 | { |
| 635 | qDebug() << "Will load group list now."; |
| 636 | |
| 637 | QString groupFileName = m_instDir + "/instgroups.json"; |
| 638 | |
| 639 | // if there's no group file, fail |
| 640 | if (!QFileInfo(groupFileName).exists()) |
| 641 | return; |
| 642 | |
| 643 | QByteArray jsonData; |
| 644 | try |
| 645 | { |
| 646 | jsonData = FS::read(groupFileName); |
| 647 | } |
| 648 | catch (const FS::FileSystemException &e) |
| 649 | { |
| 650 | qCritical() << "Failed to read instance group file :" << e.cause(); |
| 651 | return; |
| 652 | } |
| 653 | |
| 654 | QJsonParseError error; |
| 655 | QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonData, &error); |
| 656 | |
| 657 | // if the json was bad, fail |
| 658 | if (error.error != QJsonParseError::NoError) |
| 659 | { |
| 660 | qCritical() << QString("Failed to parse instance group file: %1 at offset %2") |
| 661 | .arg(error.errorString(), QString::number(error.offset)) |
| 662 | .toUtf8(); |
| 663 | return; |
| 664 | } |
| 665 | |
| 666 | // if the root of the json wasn't an object, fail |
| 667 | if (!jsonDoc.isObject()) |
| 668 | { |
| 669 | qWarning() << "Invalid group file. Root entry should be an object."; |
| 670 | return; |
| 671 | } |
| 672 | |
| 673 | QJsonObject rootObj = jsonDoc.object(); |
| 674 | |
| 675 | // Make sure the format version matches, otherwise fail. |
| 676 | if (rootObj.value("formatVersion").toVariant().toInt() != GROUP_FILE_FORMAT_VERSION) |
| 677 | return; |
| 678 | |
| 679 | // Get the groups. if it's not an object, fail |
| 680 | if (!rootObj.value("groups").isObject()) |
| 681 | { |
| 682 | qWarning() << "Invalid group list JSON: 'groups' should be an object."; |
| 683 | return; |
| 684 | } |
| 685 | |
| 686 | QSet<QString> groupSet; |
| 687 | m_instanceGroupIndex.clear(); |
| 688 | |
| 689 | // Iterate through all the groups. |
| 690 | QJsonObject groupMapping = rootObj.value("groups").toObject(); |
nothing calls this directly
no test coverage detected