| 624 | } |
| 625 | |
| 626 | void LemonLime::loadContest(const QString &filePath) { |
| 627 | if (curContest) |
| 628 | closeAction(); |
| 629 | |
| 630 | curContest = new Contest(this); |
| 631 | |
| 632 | QFile file(filePath); |
| 633 | |
| 634 | if (! file.open(QFile::ReadOnly)) { |
| 635 | QMessageBox::warning(this, tr("Error"), tr("Cannot open file %1").arg(QFileInfo(filePath).fileName()), |
| 636 | QMessageBox::Close); |
| 637 | return; |
| 638 | } |
| 639 | char firstChar; |
| 640 | file.peek(&firstChar, 1); |
| 641 | // Don't support RFC 7159, but support RFC 4627 |
| 642 | if (firstChar == '[' || firstChar == '{') { |
| 643 | QJsonParseError parseError; |
| 644 | QJsonObject inObj(QJsonDocument::fromJson(file.readAll(), &parseError).object()); |
| 645 | if (parseError.error != 0) { |
| 646 | QMessageBox::warning(this, tr("Error"), |
| 647 | tr("File %1 is broken").arg(QFileInfo(filePath).fileName()) + "\n" + |
| 648 | parseError.errorString() + "at position" + |
| 649 | QString("%1").arg(parseError.offset), |
| 650 | QMessageBox::Close); |
| 651 | return; |
| 652 | } |
| 653 | QApplication::setOverrideCursor(Qt::WaitCursor); |
| 654 | curContest->setSettings(settings); |
| 655 | if (curContest->readFromJson(inObj) == -1) { |
| 656 | QMessageBox::warning(this, tr("Error"), |
| 657 | tr("File %1 is broken").arg(QFileInfo(filePath).fileName()), |
| 658 | QMessageBox::Close); |
| 659 | QApplication::restoreOverrideCursor(); |
| 660 | return; |
| 661 | } |
| 662 | } else { |
| 663 | QDataStream _in(&file); |
| 664 | unsigned checkNumber = 0; |
| 665 | _in >> checkNumber; |
| 666 | |
| 667 | if (checkNumber != unsigned(MagicNumber)) { |
| 668 | QMessageBox::warning(this, tr("Error"), |
| 669 | tr("File %1 is broken").arg(QFileInfo(filePath).fileName()), |
| 670 | QMessageBox::Close); |
| 671 | return; |
| 672 | } |
| 673 | |
| 674 | quint16 checksum = 0; |
| 675 | int len = 0; |
| 676 | _in >> checksum >> len; |
| 677 | char *raw = new char[len]; |
| 678 | _in.readRawData(raw, len); |
| 679 | |
| 680 | if (qChecksum(QByteArrayView(raw, static_cast<uint>(len))) != checksum) { |
| 681 | QMessageBox::warning(this, tr("Error"), |
| 682 | tr("File %1 is broken").arg(QFileInfo(filePath).fileName()), |
| 683 | QMessageBox::Close); |
nothing calls this directly
no test coverage detected