1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-22 22:13:35 +02:00

Support redirecting downloads

This commit is contained in:
nordsoft 2022-08-27 19:59:50 +04:00
parent 5cb1097053
commit 03e7b5d39f
2 changed files with 20 additions and 0 deletions

View File

@ -20,6 +20,7 @@ CDownloadManager::CDownloadManager()
void CDownloadManager::downloadFile(const QUrl & url, const QString & file)
{
filename = file;
QNetworkRequest request(url);
FileEntry entry;
entry.file.reset(new QFile(CLauncherDirs::get().downloadsPath() + '/' + file));
@ -61,6 +62,23 @@ CDownloadManager::FileEntry & CDownloadManager::getEntry(QNetworkReply * reply)
void CDownloadManager::downloadFinished(QNetworkReply * reply)
{
FileEntry & file = getEntry(reply);
QVariant possibleRedirectUrl = reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
QUrl qurl = possibleRedirectUrl.toUrl();
if(possibleRedirectUrl.isValid())
{
for(int i = 0; i< currentDownloads.size(); ++i)
{
if(currentDownloads[i].file == file.file)
{
currentDownloads.removeAt(i);
break;
}
}
downloadFile(qurl, filename);
return;
}
if(file.reply->error())
{

View File

@ -35,6 +35,8 @@ class CDownloadManager : public QObject
};
QStringList encounteredErrors;
QString filename;
QNetworkAccessManager manager;