mirror of
https://github.com/PrismLauncher/PrismLauncher.git
synced 2025-06-12 05:07:46 +02:00
Added file logger
This commit is contained in:
@ -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;
|
||||
}
|
||||
|
@ -21,4 +21,4 @@ protected slots:
|
||||
void downloadReadyRead();
|
||||
};
|
||||
|
||||
typedef QSharedPointer<ByteArrayDownload> ByteArrayDownloadPtr;
|
||||
typedef std::shared_ptr<ByteArrayDownload> ByteArrayDownloadPtr;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -31,4 +31,4 @@ public slots:
|
||||
virtual void start();
|
||||
};
|
||||
|
||||
typedef QSharedPointer<CacheDownload> CacheDownloadPtr;
|
||||
typedef std::shared_ptr<CacheDownload> CacheDownloadPtr;
|
||||
|
@ -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;
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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.
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -32,4 +32,4 @@ public slots:
|
||||
virtual void start();
|
||||
};
|
||||
|
||||
typedef QSharedPointer<FileDownload> FileDownloadPtr;
|
||||
typedef std::shared_ptr<FileDownload> FileDownloadPtr;
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -32,4 +32,4 @@ private:
|
||||
void decompressAndInstall();
|
||||
};
|
||||
|
||||
typedef QSharedPointer<ForgeXzDownload> ForgeXzDownloadPtr;
|
||||
typedef std::shared_ptr<ForgeXzDownload> ForgeXzDownloadPtr;
|
||||
|
@ -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;
|
||||
|
@ -15,7 +15,7 @@ struct MetaEntry
|
||||
QString getFullPath();
|
||||
};
|
||||
|
||||
typedef QSharedPointer<MetaEntry> MetaEntryPtr;
|
||||
typedef std::shared_ptr<MetaEntry> MetaEntryPtr;
|
||||
|
||||
class HttpMetaCache : public QObject
|
||||
{
|
||||
|
@ -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 *)));
|
||||
|
||||
/*
|
||||
|
Reference in New Issue
Block a user