summaryrefslogtreecommitdiffstats
path: root/api/logic/minecraft/forge/ForgeXzDownload.cpp
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2016-08-14 02:33:31 +0200
committerPetr Mrázek <peterix@gmail.com>2016-08-14 23:22:54 +0200
commit042f3ef55c0b469f438542152c4eb02b0789ea3c (patch)
tree03e0c15b200786558babd0fe58edac88ed1bfd1e /api/logic/minecraft/forge/ForgeXzDownload.cpp
parent2f0441b3c1cd9fc3bcb176d2852da8f92a6e6777 (diff)
downloadMultiMC-042f3ef55c0b469f438542152c4eb02b0789ea3c.tar
MultiMC-042f3ef55c0b469f438542152c4eb02b0789ea3c.tar.gz
MultiMC-042f3ef55c0b469f438542152c4eb02b0789ea3c.tar.lz
MultiMC-042f3ef55c0b469f438542152c4eb02b0789ea3c.tar.xz
MultiMC-042f3ef55c0b469f438542152c4eb02b0789ea3c.zip
GH-352 Make OneSix instance update downloads cancellable
Diffstat (limited to 'api/logic/minecraft/forge/ForgeXzDownload.cpp')
-rw-r--r--api/logic/minecraft/forge/ForgeXzDownload.cpp44
1 files changed, 40 insertions, 4 deletions
diff --git a/api/logic/minecraft/forge/ForgeXzDownload.cpp b/api/logic/minecraft/forge/ForgeXzDownload.cpp
index adf96552..8b762866 100644
--- a/api/logic/minecraft/forge/ForgeXzDownload.cpp
+++ b/api/logic/minecraft/forge/ForgeXzDownload.cpp
@@ -35,6 +35,12 @@ ForgeXzDownload::ForgeXzDownload(QString relative_path, MetaEntryPtr entry) : Ne
void ForgeXzDownload::start()
{
+ if(m_status == Job_Aborted)
+ {
+ qWarning() << "Attempt to start an aborted Download:" << m_url.toString();
+ emit aborted(m_index_within_job);
+ return;
+ }
m_status = Job_InProgress;
if (!m_entry->isStale())
{
@@ -76,9 +82,17 @@ void ForgeXzDownload::downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
void ForgeXzDownload::downloadError(QNetworkReply::NetworkError error)
{
- // error happened during download.
- // TODO: log the reason why
- m_status = Job_Failed;
+ if(error == QNetworkReply::OperationCanceledError)
+ {
+ qCritical() << "Aborted " << m_url.toString();
+ m_status = Job_Aborted;
+ }
+ else
+ {
+ // error happened during download.
+ qCritical() << "Failed " << m_url.toString() << " with reason " << error;
+ m_status = Job_Failed;
+ }
}
void ForgeXzDownload::failAndTryNextMirror()
@@ -90,7 +104,7 @@ void ForgeXzDownload::failAndTryNextMirror()
void ForgeXzDownload::downloadFinished()
{
// if the download succeeded
- if (m_status != Job_Failed)
+ if (m_status != Job_Failed && m_status != Job_Aborted)
{
// nothing went wrong...
m_status = Job_Finished;
@@ -110,6 +124,14 @@ void ForgeXzDownload::downloadFinished()
return;
}
}
+ else if(m_status == Job_Aborted)
+ {
+ m_pack200_xz_file.remove();
+ m_reply.reset();
+ emit failed(m_index_within_job);
+ emit aborted(m_index_within_job);
+ return;
+ }
// else the download failed
else
{
@@ -147,6 +169,7 @@ void ForgeXzDownload::downloadReadyRead()
const size_t buffer_size = 8196;
+// NOTE: once this gets here, it can't be aborted anymore. we don't care.
void ForgeXzDownload::decompressAndInstall()
{
// rewind the downloaded temp file
@@ -356,3 +379,16 @@ void ForgeXzDownload::decompressAndInstall()
m_reply.reset();
emit succeeded(m_index_within_job);
}
+
+bool ForgeXzDownload::abort()
+{
+ if(m_reply)
+ m_reply->abort();
+ m_status = Job_Aborted;
+ return true;
+}
+
+bool ForgeXzDownload::canAbort()
+{
+ return true;
+}