| 34 | } |
| 35 | |
| 36 | void OpenContestWidget::refreshContestList() { |
| 37 | ui->recentContest->setRowCount(0); |
| 38 | |
| 39 | for (int i = 0; i < recentContest.size();) { |
| 40 | QFile file(recentContest[i]); |
| 41 | |
| 42 | if (! file.open(QFile::ReadOnly)) { |
| 43 | recentContest.removeAt(i); |
| 44 | continue; |
| 45 | } |
| 46 | QString title; |
| 47 | char firstChar; |
| 48 | file.peek(&firstChar, 1); |
| 49 | // Don't support RFC 7159, but support RFC 4627 |
| 50 | if (firstChar == '[' || firstChar == '{') { |
| 51 | QJsonParseError parseError; |
| 52 | QJsonObject inObj(QJsonDocument::fromJson(file.readAll(), &parseError).object()); |
| 53 | if (parseError.error != 0) { |
| 54 | recentContest.removeAt(i); |
| 55 | continue; |
| 56 | } |
| 57 | title = inObj["contestTitle"].toString(); |
| 58 | } else { |
| 59 | QDataStream _in(&file); |
| 60 | unsigned checkNumber = 0; |
| 61 | _in >> checkNumber; |
| 62 | |
| 63 | if (checkNumber != unsigned(MagicNumber)) { |
| 64 | recentContest.removeAt(i); |
| 65 | continue; |
| 66 | } |
| 67 | |
| 68 | quint16 checksum = 0; |
| 69 | int len = 0; |
| 70 | _in >> checksum >> len; |
| 71 | char *raw = new char[len]; |
| 72 | _in.readRawData(raw, len); |
| 73 | |
| 74 | if (qChecksum(QByteArrayView(raw, static_cast<uint>(len))) != checksum) { |
| 75 | delete[] raw; |
| 76 | recentContest.removeAt(i); |
| 77 | continue; |
| 78 | } |
| 79 | |
| 80 | QByteArray data(raw, len); |
| 81 | delete[] raw; |
| 82 | data = qUncompress(data); |
| 83 | QDataStream in(data); |
| 84 | in >> title; |
| 85 | } |
| 86 | ui->recentContest->setRowCount(i + 1); |
| 87 | ui->recentContest->setItem(i, 0, new QTableWidgetItem(title)); |
| 88 | ui->recentContest->setItem(i, 1, new QTableWidgetItem(recentContest[i])); |
| 89 | ui->recentContest->item(i, 0)->setTextAlignment(Qt::AlignCenter); |
| 90 | i++; |
| 91 | } |
| 92 | |
| 93 | QHeaderView *header = ui->recentContest->horizontalHeader(); |
nothing calls this directly
no outgoing calls
no test coverage detected