summaryrefslogtreecommitdiffstats
path: root/logic/net
diff options
context:
space:
mode:
Diffstat (limited to 'logic/net')
-rw-r--r--logic/net/ByteArrayDownload.cpp13
-rw-r--r--logic/net/ByteArrayDownload.h2
-rw-r--r--logic/net/CacheDownload.cpp10
-rw-r--r--logic/net/CacheDownload.h2
-rw-r--r--logic/net/Download.h18
-rw-r--r--logic/net/DownloadJob.cpp22
-rw-r--r--logic/net/DownloadJob.h2
-rw-r--r--logic/net/FileDownload.cpp12
-rw-r--r--logic/net/FileDownload.h2
-rw-r--r--logic/net/ForgeXzDownload.cpp26
-rw-r--r--logic/net/ForgeXzDownload.h2
-rw-r--r--logic/net/HttpMetaCache.cpp6
-rw-r--r--logic/net/HttpMetaCache.h2
-rw-r--r--logic/net/LoginTask.cpp4
14 files changed, 62 insertions, 61 deletions
diff --git a/logic/net/ByteArrayDownload.cpp b/logic/net/ByteArrayDownload.cpp
index b7a68c60..ba771eef 100644
--- a/logic/net/ByteArrayDownload.cpp
+++ b/logic/net/ByteArrayDownload.cpp
@@ -1,6 +1,6 @@
#include "ByteArrayDownload.h"
#include "MultiMC.h"
-#include <QDebug>
+#include <logger/QsLog.h>
ByteArrayDownload::ByteArrayDownload(QUrl url) : Download()
{
@@ -10,13 +10,13 @@ ByteArrayDownload::ByteArrayDownload(QUrl url) : Download()
void ByteArrayDownload::start()
{
- qDebug() << "Downloading " << m_url.toString();
+ QLOG_INFO() << "Downloading " << m_url.toString();
QNetworkRequest request(m_url);
request.setHeader(QNetworkRequest::UserAgentHeader, "MultiMC/5.0 (Uncached)");
auto worker = MMC->qnam();
QNetworkReply *rep = worker->get(request);
- m_reply = QSharedPointer<QNetworkReply>(rep, &QObject::deleteLater);
+ m_reply = std::shared_ptr<QNetworkReply>(rep);
connect(rep, SIGNAL(downloadProgress(qint64, qint64)),
SLOT(downloadProgress(qint64, qint64)));
connect(rep, SIGNAL(finished()), SLOT(downloadFinished()));
@@ -33,7 +33,8 @@ void ByteArrayDownload::downloadProgress(qint64 bytesReceived, qint64 bytesTotal
void ByteArrayDownload::downloadError(QNetworkReply::NetworkError error)
{
// error happened during download.
- qDebug() << "URL:" << m_url.toString().toLocal8Bit() << "Network error: " << error;
+ QLOG_ERROR() << "Error getting URL:" << m_url.toString().toLocal8Bit()
+ << "Network error: " << error;
m_status = Job_Failed;
}
@@ -45,14 +46,14 @@ void ByteArrayDownload::downloadFinished()
// nothing went wrong...
m_status = Job_Finished;
m_data = m_reply->readAll();
- m_reply.clear();
+ m_reply.reset();
emit succeeded(index_within_job);
return;
}
// else the download failed
else
{
- m_reply.clear();
+ m_reply.reset();
emit failed(index_within_job);
return;
}
diff --git a/logic/net/ByteArrayDownload.h b/logic/net/ByteArrayDownload.h
index 428b21db..cfc6a8d0 100644
--- a/logic/net/ByteArrayDownload.h
+++ b/logic/net/ByteArrayDownload.h
@@ -21,4 +21,4 @@ protected slots:
void downloadReadyRead();
};
-typedef QSharedPointer<ByteArrayDownload> ByteArrayDownloadPtr;
+typedef std::shared_ptr<ByteArrayDownload> ByteArrayDownloadPtr;
diff --git a/logic/net/CacheDownload.cpp b/logic/net/CacheDownload.cpp
index 9fc1f127..0e653e05 100644
--- a/logic/net/CacheDownload.cpp
+++ b/logic/net/CacheDownload.cpp
@@ -5,7 +5,7 @@
#include <QCryptographicHash>
#include <QFileInfo>
#include <QDateTime>
-#include <QDebug>
+#include <logger/QsLog.h>
CacheDownload::CacheDownload(QUrl url, MetaEntryPtr entry)
: Download(), md5sum(QCryptographicHash::Md5)
@@ -31,7 +31,7 @@ void CacheDownload::start()
emit failed(index_within_job);
return;
}
- qDebug() << "Downloading " << m_url.toString();
+ QLOG_INFO() << "Downloading " << m_url.toString();
QNetworkRequest request(m_url);
request.setRawHeader(QString("If-None-Match").toLatin1(), m_entry->etag.toLatin1());
request.setHeader(QNetworkRequest::UserAgentHeader,"MultiMC/5.0 (Cached)");
@@ -39,7 +39,7 @@ void CacheDownload::start()
auto worker = MMC->qnam();
QNetworkReply *rep = worker->get(request);
- m_reply = QSharedPointer<QNetworkReply>(rep, &QObject::deleteLater);
+ m_reply = std::shared_ptr<QNetworkReply>(rep);
connect(rep, SIGNAL(downloadProgress(qint64, qint64)),
SLOT(downloadProgress(qint64, qint64)));
connect(rep, SIGNAL(finished()), SLOT(downloadFinished()));
@@ -92,7 +92,7 @@ void CacheDownload::downloadFinished()
m_entry->stale = false;
MMC->metacache()->updateEntry(m_entry);
- m_reply.clear();
+ m_reply.reset();
emit succeeded(index_within_job);
return;
}
@@ -101,7 +101,7 @@ void CacheDownload::downloadFinished()
{
m_output_file.close();
m_output_file.remove();
- m_reply.clear();
+ m_reply.reset();
emit failed(index_within_job);
return;
}
diff --git a/logic/net/CacheDownload.h b/logic/net/CacheDownload.h
index f95dabd5..295391b1 100644
--- a/logic/net/CacheDownload.h
+++ b/logic/net/CacheDownload.h
@@ -31,4 +31,4 @@ public slots:
virtual void start();
};
-typedef QSharedPointer<CacheDownload> CacheDownloadPtr;
+typedef std::shared_ptr<CacheDownload> CacheDownloadPtr;
diff --git a/logic/net/Download.h b/logic/net/Download.h
index 91f09dec..ca4bee9f 100644
--- a/logic/net/Download.h
+++ b/logic/net/Download.h
@@ -2,10 +2,9 @@
#include <QObject>
#include <QUrl>
-#include <QSharedPointer>
+#include <memory>
#include <QNetworkReply>
-
enum JobStatus
{
Job_NotStarted,
@@ -18,20 +17,21 @@ class Download : public QObject
{
Q_OBJECT
protected:
- explicit Download(): QObject(0){};
+ explicit Download() : QObject(0) {};
+
public:
virtual ~Download() {};
public:
/// the network reply
- QSharedPointer<QNetworkReply> m_reply;
-
+ std::shared_ptr<QNetworkReply> m_reply;
+
/// source URL
QUrl m_url;
-
+
/// The file's status
JobStatus m_status;
-
+
/// index within the parent job
int index_within_job = 0;
@@ -46,9 +46,9 @@ protected slots:
virtual void downloadError(QNetworkReply::NetworkError error) = 0;
virtual void downloadFinished() = 0;
virtual void downloadReadyRead() = 0;
-
+
public slots:
virtual void start() = 0;
};
-typedef QSharedPointer<Download> DownloadPtr;
+typedef std::shared_ptr<Download> DownloadPtr;
diff --git a/logic/net/DownloadJob.cpp b/logic/net/DownloadJob.cpp
index 03a69555..f6275b7a 100644
--- a/logic/net/DownloadJob.cpp
+++ b/logic/net/DownloadJob.cpp
@@ -5,7 +5,7 @@
#include "ByteArrayDownload.h"
#include "CacheDownload.h"
-#include <QDebug>
+#include <logger/QsLog.h>
ByteArrayDownloadPtr DownloadJob::addByteArrayDownload(QUrl url)
{
@@ -54,18 +54,18 @@ void DownloadJob::partSucceeded(int index)
partProgress(index, slot.total_progress, slot.total_progress);
num_succeeded++;
- qDebug() << m_job_name.toLocal8Bit() << " progress: " << num_succeeded << "/"
+ QLOG_INFO() << m_job_name.toLocal8Bit() << " progress: " << num_succeeded << "/"
<< downloads.size();
if (num_failed + num_succeeded == downloads.size())
{
if (num_failed)
{
- qDebug() << m_job_name.toLocal8Bit() << " failed.";
+ QLOG_ERROR() << m_job_name.toLocal8Bit() << " failed.";
emit failed();
}
else
{
- qDebug() << m_job_name.toLocal8Bit() << " succeeded.";
+ QLOG_INFO() << m_job_name.toLocal8Bit() << " succeeded.";
emit succeeded();
}
}
@@ -76,17 +76,17 @@ void DownloadJob::partFailed(int index)
auto &slot = parts_progress[index];
if (slot.failures == 3)
{
- qDebug() << "Part " << index << " failed 3 times (" << downloads[index]->m_url << ")";
+ QLOG_ERROR() << "Part " << index << " failed 3 times (" << downloads[index]->m_url << ")";
num_failed++;
if (num_failed + num_succeeded == downloads.size())
{
- qDebug() << m_job_name.toLocal8Bit() << " failed.";
+ QLOG_ERROR() << m_job_name.toLocal8Bit() << " failed.";
emit failed();
}
}
else
{
- qDebug() << "Part " << index << " failed, restarting (" << downloads[index]->m_url
+ QLOG_ERROR() << "Part " << index << " failed, restarting (" << downloads[index]->m_url
<< ")";
// restart the job
slot.failures++;
@@ -110,12 +110,12 @@ void DownloadJob::partProgress(int index, qint64 bytesReceived, qint64 bytesTota
void DownloadJob::start()
{
- qDebug() << m_job_name.toLocal8Bit() << " started.";
+ QLOG_INFO() << m_job_name.toLocal8Bit() << " started.";
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)),
+ connect(iter.get(), SIGNAL(succeeded(int)), SLOT(partSucceeded(int)));
+ connect(iter.get(), SIGNAL(failed(int)), SLOT(partFailed(int)));
+ connect(iter.get(), SIGNAL(progress(int, qint64, qint64)),
SLOT(partProgress(int, qint64, qint64)));
iter->start();
}
diff --git a/logic/net/DownloadJob.h b/logic/net/DownloadJob.h
index 8c32950a..91b014ad 100644
--- a/logic/net/DownloadJob.h
+++ b/logic/net/DownloadJob.h
@@ -9,7 +9,7 @@
#include "logic/tasks/ProgressProvider.h"
class DownloadJob;
-typedef QSharedPointer<DownloadJob> DownloadJobPtr;
+typedef std::shared_ptr<DownloadJob> DownloadJobPtr;
/**
* A single file for the downloader/cache to process.
diff --git a/logic/net/FileDownload.cpp b/logic/net/FileDownload.cpp
index 353fd58b..3f38b0fa 100644
--- a/logic/net/FileDownload.cpp
+++ b/logic/net/FileDownload.cpp
@@ -2,7 +2,7 @@
#include "FileDownload.h"
#include <pathutils.h>
#include <QCryptographicHash>
-#include <QDebug>
+#include <logger/QsLog.h>
FileDownload::FileDownload ( QUrl url, QString target_path )
@@ -28,7 +28,7 @@ void FileDownload::start()
// skip this file if they match
if ( m_check_md5 && hash == m_expected_md5 )
{
- qDebug() << "Skipping " << m_url.toString() << ": md5 match.";
+ QLOG_INFO() << "Skipping " << m_url.toString() << ": md5 match.";
emit succeeded(index_within_job);
return;
}
@@ -43,7 +43,7 @@ void FileDownload::start()
return;
}
- qDebug() << "Downloading " << m_url.toString();
+ QLOG_INFO() << "Downloading " << m_url.toString();
QNetworkRequest request ( m_url );
request.setRawHeader(QString("If-None-Match").toLatin1(), m_expected_md5.toLatin1());
request.setHeader(QNetworkRequest::UserAgentHeader,"MultiMC/5.0 (Uncached)");
@@ -51,7 +51,7 @@ void FileDownload::start()
auto worker = MMC->qnam();
QNetworkReply * rep = worker->get ( request );
- m_reply = QSharedPointer<QNetworkReply> ( rep, &QObject::deleteLater );
+ m_reply = std::shared_ptr<QNetworkReply> ( rep );
connect ( rep, SIGNAL ( downloadProgress ( qint64,qint64 ) ), SLOT ( downloadProgress ( qint64,qint64 ) ) );
connect ( rep, SIGNAL ( finished() ), SLOT ( downloadFinished() ) );
connect ( rep, SIGNAL ( error ( QNetworkReply::NetworkError ) ), SLOT ( downloadError ( QNetworkReply::NetworkError ) ) );
@@ -79,7 +79,7 @@ void FileDownload::downloadFinished()
m_status = Job_Finished;
m_output_file.close();
- m_reply.clear();
+ m_reply.reset();
emit succeeded(index_within_job);
return;
}
@@ -87,7 +87,7 @@ void FileDownload::downloadFinished()
else
{
m_output_file.close();
- m_reply.clear();
+ m_reply.reset();
emit failed(index_within_job);
return;
}
diff --git a/logic/net/FileDownload.h b/logic/net/FileDownload.h
index 190bee58..9abb590d 100644
--- a/logic/net/FileDownload.h
+++ b/logic/net/FileDownload.h
@@ -32,4 +32,4 @@ public slots:
virtual void start();
};
-typedef QSharedPointer<FileDownload> FileDownloadPtr;
+typedef std::shared_ptr<FileDownload> FileDownloadPtr;
diff --git a/logic/net/ForgeXzDownload.cpp b/logic/net/ForgeXzDownload.cpp
index 6d66abce..3ec2155b 100644
--- a/logic/net/ForgeXzDownload.cpp
+++ b/logic/net/ForgeXzDownload.cpp
@@ -5,7 +5,7 @@
#include <QCryptographicHash>
#include <QFileInfo>
#include <QDateTime>
-#include <QDebug>
+#include <logger/QsLog.h>
ForgeXzDownload::ForgeXzDownload(QUrl url, MetaEntryPtr entry)
: Download()
@@ -32,7 +32,7 @@ void ForgeXzDownload::start()
emit failed(index_within_job);
return;
}
- qDebug() << "Downloading " << m_url.toString();
+ QLOG_INFO() << "Downloading " << m_url.toString();
QNetworkRequest request(m_url);
request.setRawHeader(QString("If-None-Match").toLatin1(), m_entry->etag.toLatin1());
request.setHeader(QNetworkRequest::UserAgentHeader,"MultiMC/5.0 (Cached)");
@@ -40,7 +40,7 @@ void ForgeXzDownload::start()
auto worker = MMC->qnam();
QNetworkReply *rep = worker->get(request);
- m_reply = QSharedPointer<QNetworkReply>(rep, &QObject::deleteLater);
+ m_reply = std::shared_ptr<QNetworkReply>(rep);
connect(rep, SIGNAL(downloadProgress(qint64, qint64)),
SLOT(downloadProgress(qint64, qint64)));
connect(rep, SIGNAL(finished()), SLOT(downloadFinished()));
@@ -78,7 +78,7 @@ void ForgeXzDownload::downloadFinished()
{
// something bad happened
m_pack200_xz_file.remove();
- m_reply.clear();
+ m_reply.reset();
emit failed(index_within_job);
return;
}
@@ -88,7 +88,7 @@ void ForgeXzDownload::downloadFinished()
{
m_pack200_xz_file.close();
m_pack200_xz_file.remove();
- m_reply.clear();
+ m_reply.reset();
emit failed(index_within_job);
return;
}
@@ -198,38 +198,38 @@ void ForgeXzDownload::decompressAndInstall()
break;
case XZ_MEM_ERROR:
- qDebug() << "Memory allocation failed\n";
+ QLOG_ERROR() << "Memory allocation failed\n";
xz_dec_end(s);
emit failed(index_within_job);
return;
case XZ_MEMLIMIT_ERROR:
- qDebug() << "Memory usage limit reached\n";
+ QLOG_ERROR() << "Memory usage limit reached\n";
xz_dec_end(s);
emit failed(index_within_job);
return;
case XZ_FORMAT_ERROR:
- qDebug() << "Not a .xz file\n";
+ QLOG_ERROR() << "Not a .xz file\n";
xz_dec_end(s);
emit failed(index_within_job);
return;
case XZ_OPTIONS_ERROR:
- qDebug() << "Unsupported options in the .xz headers\n";
+ QLOG_ERROR() << "Unsupported options in the .xz headers\n";
xz_dec_end(s);
emit failed(index_within_job);
return;
case XZ_DATA_ERROR:
case XZ_BUF_ERROR:
- qDebug() << "File is corrupt\n";
+ QLOG_ERROR() << "File is corrupt\n";
xz_dec_end(s);
emit failed(index_within_job);
return;
default:
- qDebug() << "Bug!\n";
+ QLOG_ERROR() << "Bug!\n";
xz_dec_end(s);
emit failed(index_within_job);
return;
@@ -246,7 +246,7 @@ void ForgeXzDownload::decompressAndInstall()
}
catch(std::runtime_error & err)
{
- qDebug() << "Error unpacking " << pack_name.toUtf8() << " : " << err.what();
+ QLOG_ERROR() << "Error unpacking " << pack_name.toUtf8() << " : " << err.what();
QFile f(m_target_path);
if(f.exists())
f.remove();
@@ -274,6 +274,6 @@ void ForgeXzDownload::decompressAndInstall()
m_entry->stale = false;
MMC->metacache()->updateEntry(m_entry);
- m_reply.clear();
+ m_reply.reset();
emit succeeded(index_within_job);
}
diff --git a/logic/net/ForgeXzDownload.h b/logic/net/ForgeXzDownload.h
index 8cb47783..5d677947 100644
--- a/logic/net/ForgeXzDownload.h
+++ b/logic/net/ForgeXzDownload.h
@@ -32,4 +32,4 @@ private:
void decompressAndInstall();
};
-typedef QSharedPointer<ForgeXzDownload> ForgeXzDownloadPtr;
+typedef std::shared_ptr<ForgeXzDownload> ForgeXzDownloadPtr;
diff --git a/logic/net/HttpMetaCache.cpp b/logic/net/HttpMetaCache.cpp
index 46801ab3..9c642a0f 100644
--- a/logic/net/HttpMetaCache.cpp
+++ b/logic/net/HttpMetaCache.cpp
@@ -9,7 +9,7 @@
#include <QDateTime>
#include <QCryptographicHash>
-#include <QDebug>
+#include <logger/QsLog.h>
#include <QJsonDocument>
#include <QJsonArray>
@@ -105,12 +105,12 @@ bool HttpMetaCache::updateEntry ( MetaEntryPtr stale_entry )
{
if(!m_entries.contains(stale_entry->base))
{
- qDebug() << "Cannot add entry with unknown base: " << stale_entry->base.toLocal8Bit();
+ QLOG_ERROR() << "Cannot add entry with unknown base: " << stale_entry->base.toLocal8Bit();
return false;
}
if(stale_entry->stale)
{
- qDebug() << "Cannot add stale entry: " << stale_entry->getFullPath().toLocal8Bit();
+ QLOG_ERROR() << "Cannot add stale entry: " << stale_entry->getFullPath().toLocal8Bit();
return false;
}
m_entries[stale_entry->base].entry_list[stale_entry->path] = stale_entry;
diff --git a/logic/net/HttpMetaCache.h b/logic/net/HttpMetaCache.h
index daf6c43f..8107839e 100644
--- a/logic/net/HttpMetaCache.h
+++ b/logic/net/HttpMetaCache.h
@@ -15,7 +15,7 @@ struct MetaEntry
QString getFullPath();
};
-typedef QSharedPointer<MetaEntry> MetaEntryPtr;
+typedef std::shared_ptr<MetaEntry> MetaEntryPtr;
class HttpMetaCache : public QObject
{
diff --git a/logic/net/LoginTask.cpp b/logic/net/LoginTask.cpp
index 2a45400e..5de8efa9 100644
--- a/logic/net/LoginTask.cpp
+++ b/logic/net/LoginTask.cpp
@@ -40,7 +40,7 @@ void LoginTask::legacyLogin()
{
setStatus(tr("Logging in..."));
auto worker = MMC->qnam();
- connect(worker.data(), SIGNAL(finished(QNetworkReply *)), this,
+ connect(worker.get(), SIGNAL(finished(QNetworkReply *)), this,
SLOT(processLegacyReply(QNetworkReply *)));
QUrl loginURL("https://login.minecraft.net/");
@@ -134,7 +134,7 @@ void LoginTask::yggdrasilLogin()
{
setStatus(tr("Logging in..."));
auto worker = MMC->qnam();
- connect(worker.data(), SIGNAL(finished(QNetworkReply *)), this,
+ connect(worker.get(), SIGNAL(finished(QNetworkReply *)), this,
SLOT(processYggdrasilReply(QNetworkReply *)));
/*