From f83119ce7ec3d11a903901b8eff762d2b0a9f635 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sun, 6 Oct 2013 01:13:40 +0200 Subject: Added file logger --- logic/net/ByteArrayDownload.cpp | 13 +++++++------ logic/net/ByteArrayDownload.h | 2 +- logic/net/CacheDownload.cpp | 10 +++++----- logic/net/CacheDownload.h | 2 +- logic/net/Download.h | 18 +++++++++--------- logic/net/DownloadJob.cpp | 22 +++++++++++----------- logic/net/DownloadJob.h | 2 +- logic/net/FileDownload.cpp | 12 ++++++------ logic/net/FileDownload.h | 2 +- logic/net/ForgeXzDownload.cpp | 26 +++++++++++++------------- logic/net/ForgeXzDownload.h | 2 +- logic/net/HttpMetaCache.cpp | 6 +++--- logic/net/HttpMetaCache.h | 2 +- logic/net/LoginTask.cpp | 4 ++-- 14 files changed, 62 insertions(+), 61 deletions(-) (limited to 'logic/net') 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 +#include 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(rep, &QObject::deleteLater); + m_reply = std::shared_ptr(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 ByteArrayDownloadPtr; +typedef std::shared_ptr 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 #include #include -#include +#include 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(rep, &QObject::deleteLater); + m_reply = std::shared_ptr(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 CacheDownloadPtr; +typedef std::shared_ptr 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 #include -#include +#include #include - 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 m_reply; - + std::shared_ptr 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 DownloadPtr; +typedef std::shared_ptr 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 +#include 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 DownloadJobPtr; +typedef std::shared_ptr 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 #include -#include +#include 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 ( rep, &QObject::deleteLater ); + m_reply = std::shared_ptr ( 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 FileDownloadPtr; +typedef std::shared_ptr 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 #include #include -#include +#include 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(rep, &QObject::deleteLater); + m_reply = std::shared_ptr(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 ForgeXzDownloadPtr; +typedef std::shared_ptr 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 #include -#include +#include #include #include @@ -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 MetaEntryPtr; +typedef std::shared_ptr 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 *))); /* -- cgit v1.2.3