summaryrefslogtreecommitdiffstats
path: root/logic/net
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2013-09-26 02:58:09 +0200
committerPetr Mrázek <peterix@gmail.com>2013-09-26 02:59:56 +0200
commit2c8dc0b855c38c5204d398ad306fa9cf43be1ada (patch)
tree59429d658012a3df0e548e1a5f08100fb2930fc0 /logic/net
parentaf234f35029de8c46aefecd8b9345b30ae1c51b0 (diff)
downloadMultiMC-2c8dc0b855c38c5204d398ad306fa9cf43be1ada.tar
MultiMC-2c8dc0b855c38c5204d398ad306fa9cf43be1ada.tar.gz
MultiMC-2c8dc0b855c38c5204d398ad306fa9cf43be1ada.tar.lz
MultiMC-2c8dc0b855c38c5204d398ad306fa9cf43be1ada.tar.xz
MultiMC-2c8dc0b855c38c5204d398ad306fa9cf43be1ada.zip
Compression algo dependencies, still need hackery...
Diffstat (limited to 'logic/net')
-rw-r--r--logic/net/ByteArrayDownload.cpp2
-rw-r--r--logic/net/DownloadJob.cpp95
-rw-r--r--logic/net/DownloadJob.h9
3 files changed, 70 insertions, 36 deletions
diff --git a/logic/net/ByteArrayDownload.cpp b/logic/net/ByteArrayDownload.cpp
index 6ae3f121..61ecc298 100644
--- a/logic/net/ByteArrayDownload.cpp
+++ b/logic/net/ByteArrayDownload.cpp
@@ -31,7 +31,7 @@ void ByteArrayDownload::downloadProgress ( qint64 bytesReceived, qint64 bytesTot
void ByteArrayDownload::downloadError ( QNetworkReply::NetworkError error )
{
// error happened during download.
- // TODO: log the reason why
+ qDebug() << "URL:" << m_url.toString().toLocal8Bit() << "Network error: " << error;
m_status = Job_Failed;
}
diff --git a/logic/net/DownloadJob.cpp b/logic/net/DownloadJob.cpp
index 3acba050..8da1f39b 100644
--- a/logic/net/DownloadJob.cpp
+++ b/logic/net/DownloadJob.cpp
@@ -7,47 +7,48 @@
#include <QDebug>
-ByteArrayDownloadPtr DownloadJob::add ( QUrl url )
+ByteArrayDownloadPtr DownloadJob::add(QUrl url)
{
- ByteArrayDownloadPtr ptr (new ByteArrayDownload(url));
+ ByteArrayDownloadPtr ptr(new ByteArrayDownload(url));
ptr->index_within_job = downloads.size();
downloads.append(ptr);
- parts_progress.append(QPair<qint64, qint64>(0,1));
+ parts_progress.append(part_info());
total_progress++;
return ptr;
}
-FileDownloadPtr DownloadJob::add ( QUrl url, QString rel_target_path)
+FileDownloadPtr DownloadJob::add(QUrl url, QString rel_target_path)
{
- FileDownloadPtr ptr (new FileDownload(url, rel_target_path));
+ FileDownloadPtr ptr(new FileDownload(url, rel_target_path));
ptr->index_within_job = downloads.size();
downloads.append(ptr);
- parts_progress.append(QPair<qint64, qint64>(0,1));
+ parts_progress.append(part_info());
total_progress++;
return ptr;
}
-CacheDownloadPtr DownloadJob::add ( QUrl url, MetaEntryPtr entry)
+CacheDownloadPtr DownloadJob::add(QUrl url, MetaEntryPtr entry)
{
- CacheDownloadPtr ptr (new CacheDownload(url, entry));
+ CacheDownloadPtr ptr(new CacheDownload(url, entry));
ptr->index_within_job = downloads.size();
downloads.append(ptr);
- parts_progress.append(QPair<qint64, qint64>(0,1));
+ parts_progress.append(part_info());
total_progress++;
return ptr;
}
-void DownloadJob::partSucceeded ( int index )
+void DownloadJob::partSucceeded(int index)
{
// do progress. all slots are 1 in size at least
- auto & slot = parts_progress[index];
- partProgress ( index, slot.second , slot.second );
-
+ auto &slot = parts_progress[index];
+ partProgress(index, slot.total_progress, slot.total_progress);
+
num_succeeded++;
- qDebug() << m_job_name.toLocal8Bit() << " progress: " << num_succeeded << "/" << downloads.size();
- if(num_failed + num_succeeded == downloads.size())
+ qDebug() << m_job_name.toLocal8Bit() << " progress: " << num_succeeded << "/"
+ << downloads.size();
+ if (num_failed + num_succeeded == downloads.size())
{
- if(num_failed)
+ if (num_failed)
{
qDebug() << m_job_name.toLocal8Bit() << " failed.";
emit failed();
@@ -60,39 +61,65 @@ void DownloadJob::partSucceeded ( int index )
}
}
-void DownloadJob::partFailed ( int index )
+void DownloadJob::partFailed(int index)
{
- num_failed++;
- if(num_failed + num_succeeded == downloads.size())
+ auto &slot = parts_progress[index];
+ if (slot.failures == 3)
{
- qDebug() << m_job_name.toLocal8Bit() << " failed.";
- emit failed();
+ qDebug() << "Part " << index << " failed 3 times (" << downloads[index]->m_url << ")";
+ num_failed++;
+ if (num_failed + num_succeeded == downloads.size())
+ {
+ qDebug() << m_job_name.toLocal8Bit() << " failed.";
+ emit failed();
+ }
+ }
+ else
+ {
+ qDebug() << "Part " << index << " failed, restarting (" << downloads[index]->m_url
+ << ")";
+ // restart the job
+ slot.failures++;
+ downloads[index]->start();
}
}
-void DownloadJob::partProgress ( int index, qint64 bytesReceived, qint64 bytesTotal )
+void DownloadJob::partProgress(int index, qint64 bytesReceived, qint64 bytesTotal)
{
- auto & slot = parts_progress[index];
-
- current_progress -= slot.first;
- slot.first = bytesReceived;
- current_progress += slot.first;
-
- total_progress -= slot.second;
- slot.second = bytesTotal;
- total_progress += slot.second;
+ auto &slot = parts_progress[index];
+
+ current_progress -= slot.current_progress;
+ slot.current_progress = bytesReceived;
+ current_progress += slot.current_progress;
+
+ total_progress -= slot.total_progress;
+ slot.total_progress = bytesTotal;
+ total_progress += slot.total_progress;
emit progress(current_progress, total_progress);
}
-
void DownloadJob::start()
{
qDebug() << m_job_name.toLocal8Bit() << " started.";
- for(auto iter: downloads)
+ for (auto iter : downloads)
{
connect(iter.data(), SIGNAL(succeeded(int)), SLOT(partSucceeded(int)));
connect(iter.data(), SIGNAL(failed(int)), SLOT(partFailed(int)));
- connect(iter.data(), SIGNAL(progress(int,qint64,qint64)), SLOT(partProgress(int,qint64,qint64)));
+ connect(iter.data(), SIGNAL(progress(int, qint64, qint64)),
+ SLOT(partProgress(int, qint64, qint64)));
iter->start();
}
}
+
+QStringList DownloadJob::getFailedFiles()
+{
+ QStringList failed;
+ for (auto download : downloads)
+ {
+ if (download->m_status == Job_Failed)
+ {
+ failed.push_back(download->m_url.toString());
+ }
+ }
+ return failed;
+}
diff --git a/logic/net/DownloadJob.h b/logic/net/DownloadJob.h
index c8f6a9d7..5d5ba01a 100644
--- a/logic/net/DownloadJob.h
+++ b/logic/net/DownloadJob.h
@@ -51,6 +51,7 @@ public:
{
return m_running;
};
+ QStringList getFailedFiles();
signals:
void started();
void progress(qint64 current, qint64 total);
@@ -63,9 +64,15 @@ private slots:
void partSucceeded(int index);
void partFailed(int index);
private:
+ struct part_info
+ {
+ qint64 current_progress = 0;
+ qint64 total_progress = 1;
+ int failures = 0;
+ };
QString m_job_name;
QList<DownloadPtr> downloads;
- QList<QPair<qint64, qint64>> parts_progress;
+ QList<part_info> parts_progress;
qint64 current_progress = 0;
qint64 total_progress = 0;
int num_succeeded = 0;