void CheckFirmwareUpgradeHandler::finished(QNetworkReply *reply) { QString newVersion; QString imageLine; { QRegExp regFileMatch("(\\.*file\\.*=\\.*).*[v|V](\\d+(\\.\\d+)+).*\\.(chk|img|exe)"); QRegExp regVersionMatch("\\d+(\\.\\d+){3}"); QTextStream txtStream(reply); QString line = txtStream.readLine(); while(!line.isNull()){ line = txtStream.readLine(); if(regFileMatch.indexIn(line) != -1){ imageLine = regFileMatch.capturedTexts()[0]; if(regVersionMatch.indexIn(line) != -1){ newVersion = regVersionMatch.capturedTexts()[0]; } break; } } } reply->deleteLater(); QRegExp urlRx(QString("^(/%1/.*/).*$").arg(m_model)); int equsignIdx = imageLine.indexOf("="); if(equsignIdx == -1 || imageLine.length() <= (equsignIdx + 1) || newVersion.isEmpty()){ goto lexit; } imageLine = imageLine.mid(equsignIdx + 1); imageLine = imageLine.trimmed(); if(imageLine.isEmpty()){ goto lexit; } if(urlRx.exactMatch(imageLine)){ m_downloadUrl = QString(UPDATE_SERVER_URL) + imageLine; }else{ m_downloadUrl = QString(UPDATE_SERVER_URL) + "/" + m_model + "/" + m_region + "/" +imageLine; } m_versionOnServer = newVersion; m_dataValid = true; //qDebug () << "Download URL = " << m_downloadUrl; lexit: quit(); }
QString removeHtml(QString origText) { QString text = origText; // Remove any inline HTML tags // text.replace(QRegExp(HTML_TAG_REGEX), "<\\1>"); QRegExp rx(HTML_TAG_REGEX); QRegExp urlRx(URL_REGEX); int pos = 0; while ((pos = rx.indexIn(text, pos)) != -1) { int len = rx.matchedLength(); QString tag = rx.cap(1); if (urlRx.exactMatch(tag)) { pos += len; } else { QString newText = "<" + tag + ">"; text.replace(pos, len, newText); pos += newText.length(); } } return text; }