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:
parent
5cb1097053
commit
03e7b5d39f
@ -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())
|
||||
{
|
||||
|
@ -35,6 +35,8 @@ class CDownloadManager : public QObject
|
||||
};
|
||||
|
||||
QStringList encounteredErrors;
|
||||
|
||||
QString filename;
|
||||
|
||||
QNetworkAccessManager manager;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user