Do not attempt to download signature file, if download of update info failed already.

This commit is contained in:
LoRd_MuldeR 2014-11-17 15:42:55 +01:00
parent b2be8c9ac0
commit c57c027aac
2 changed files with 27 additions and 14 deletions

View File

@ -472,23 +472,17 @@ bool UpdateCheckThread::tryUpdateMirror(UpdateInfo *updateInfo, const QString &u
bool success = false;
log("", "Trying mirror:", url);
QString randPart = lamexp_rand_str();
QString outFileVersionInfo = QString("%1/%2.ver").arg(lamexp_temp_folder2(), randPart);
QString outFileSignature = QString("%1/%2.sig").arg(lamexp_temp_folder2(), randPart);
const QString randPart = lamexp_rand_str();
const QString outFileVers = QString("%1/%2.ver").arg(lamexp_temp_folder2(), randPart);
const QString outFileSign = QString("%1/%2.sig").arg(lamexp_temp_folder2(), randPart);
log("", "Downloading update info:");
bool ok1 = getFile(QString("%1%2").arg(url, mirror_url_postfix[m_betaUpdates ? 1 : 0]), outFileVersionInfo);
log("", "Downloading signature:");
bool ok2 = getFile(QString("%1%2.sig").arg(url, mirror_url_postfix[m_betaUpdates ? 1 : 0]), outFileSignature);
if(ok1 && ok2)
if(getUpdateInfo(url, outFileVers, outFileSign))
{
log("", "Download okay, checking signature:");
if(checkSignature(outFileVersionInfo, outFileSignature))
if(checkSignature(outFileVers, outFileSign))
{
log("", "Signature okay, parsing info:");
success = parseVersionInfo(outFileVersionInfo, updateInfo);
success = parseVersionInfo(outFileVers, updateInfo);
}
else
{
@ -500,12 +494,30 @@ bool UpdateCheckThread::tryUpdateMirror(UpdateInfo *updateInfo, const QString &u
log("", "Download has failed!");
}
QFile::remove(outFileVersionInfo);
QFile::remove(outFileSignature);
QFile::remove(outFileVers);
QFile::remove(outFileSign);
return success;
}
bool UpdateCheckThread::getUpdateInfo(const QString &url, const QString &outFileVers, const QString &outFileSign)
{
log("", "Downloading update info:");
if(!getFile(QString("%1%2" ).arg(url, mirror_url_postfix[m_betaUpdates ? 1 : 0]), outFileVers))
{
return false;
}
log("", "Downloading signature:");
if(!getFile(QString("%1%2.sig").arg(url, mirror_url_postfix[m_betaUpdates ? 1 : 0]), outFileSign))
{
return false;
}
return true;
}
bool UpdateCheckThread::getFile(const QString &url, const QString &outFile, unsigned int maxRedir, bool *httpOk)
{
QFileInfo output(outFile);

View File

@ -102,6 +102,7 @@ private:
inline void log(const QString &str1, const QString &str2 = QString(), const QString &str3 = QString(), const QString &str4 = QString());
bool getFile(const QString &url, const QString &outFile, unsigned int maxRedir = 5, bool *httpOk = NULL);
bool getUpdateInfo(const QString &url, const QString &outFileVers, const QString &outFileSign);
int tryContactHost(const QString &url);
bool tryUpdateMirror(UpdateInfo *updateInfo, const QString &url);
bool checkSignature(const QString &file, const QString &signature);