summaryrefslogtreecommitdiffstats
path: root/api/logic/net/Download.cpp
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2016-10-28 02:19:19 +0200
committerPetr Mrázek <peterix@gmail.com>2016-10-28 02:19:19 +0200
commitdd0e996081ae820a0f16b5a6854a8a6274c5edf5 (patch)
tree9d9f0ba7ff51b546d15106f71841f9de42a09f2b /api/logic/net/Download.cpp
parent3d94fb8d24c6012d5d1cdee61c99e62847c06ad9 (diff)
downloadMultiMC-dd0e996081ae820a0f16b5a6854a8a6274c5edf5.tar
MultiMC-dd0e996081ae820a0f16b5a6854a8a6274c5edf5.tar.gz
MultiMC-dd0e996081ae820a0f16b5a6854a8a6274c5edf5.tar.lz
MultiMC-dd0e996081ae820a0f16b5a6854a8a6274c5edf5.tar.xz
MultiMC-dd0e996081ae820a0f16b5a6854a8a6274c5edf5.zip
GH-1697 always stale files tolerate errors if a local copy is present
This fixes the situation when liteloader snapshot site is broken and there's an older local snapshot already present.
Diffstat (limited to 'api/logic/net/Download.cpp')
-rw-r--r--api/logic/net/Download.cpp27
1 files changed, 23 insertions, 4 deletions
diff --git a/api/logic/net/Download.cpp b/api/logic/net/Download.cpp
index 7610cae3..3d53ded0 100644
--- a/api/logic/net/Download.cpp
+++ b/api/logic/net/Download.cpp
@@ -31,10 +31,11 @@ Download::Download():NetAction()
m_status = Job_NotStarted;
}
-Download::Ptr Download::makeCached(QUrl url, MetaEntryPtr entry)
+Download::Ptr Download::makeCached(QUrl url, MetaEntryPtr entry, Options options)
{
Download * dl = new Download();
dl->m_url = url;
+ dl->m_options = options;
auto md5Node = new ChecksumValidator(QCryptographicHash::Md5);
auto cachedNode = new MetaCacheSink(entry, md5Node);
dl->m_sink.reset(cachedNode);
@@ -42,18 +43,20 @@ Download::Ptr Download::makeCached(QUrl url, MetaEntryPtr entry)
return std::shared_ptr<Download>(dl);
}
-Download::Ptr Download::makeByteArray(QUrl url, QByteArray *output)
+Download::Ptr Download::makeByteArray(QUrl url, QByteArray *output, Options options)
{
Download * dl = new Download();
dl->m_url = url;
+ dl->m_options = options;
dl->m_sink.reset(new ByteArraySink(output));
return std::shared_ptr<Download>(dl);
}
-Download::Ptr Download::makeFile(QUrl url, QString path)
+Download::Ptr Download::makeFile(QUrl url, QString path, Options options)
{
Download * dl = new Download();
dl->m_url = url;
+ dl->m_options = options;
dl->m_sink.reset(new FileSink(path));
return std::shared_ptr<Download>(dl);
}
@@ -118,6 +121,14 @@ void Download::downloadError(QNetworkReply::NetworkError error)
}
else
{
+ if(m_options & Option::AcceptLocalFiles)
+ {
+ if(m_sink->hasLocalData())
+ {
+ m_status = Job_Failed_Proceed;
+ return;
+ }
+ }
// error happened during download.
qCritical() << "Failed " << m_url.toString() << " with reason " << error;
m_status = Job_Failed;
@@ -162,7 +173,15 @@ void Download::downloadFinished()
}
// if the download failed before this point ...
- if (m_status == Job_Failed)
+ if (m_status == Job_Failed_Proceed)
+ {
+ qDebug() << "Download failed but we are allowed to proceed:" << m_url.toString();
+ m_sink->abort();
+ m_reply.reset();
+ emit succeeded(m_index_within_job);
+ return;
+ }
+ else if (m_status == Job_Failed)
{
qDebug() << "Download failed in previous step:" << m_url.toString();
m_sink->abort();