aboutsummaryrefslogtreecommitdiff
path: root/launcher/updater
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2021-11-21 23:21:12 +0100
committerPetr Mrázek <peterix@gmail.com>2021-11-21 23:21:12 +0100
commit69213b1206e97f7d4db4270a4b3b0af41dc9e6fc (patch)
treeb53ca69422ce22cceee9e648171a678679075c1a /launcher/updater
parentc2c56a2f6ceaedb8a3fa88c848b345db0fec7f9c (diff)
downloadPrismLauncher-69213b1206e97f7d4db4270a4b3b0af41dc9e6fc.tar.gz
PrismLauncher-69213b1206e97f7d4db4270a4b3b0af41dc9e6fc.tar.bz2
PrismLauncher-69213b1206e97f7d4db4270a4b3b0af41dc9e6fc.zip
NOISSUE continue refactoring things to make tests pass
Diffstat (limited to 'launcher/updater')
-rw-r--r--launcher/updater/DownloadTask.cpp14
-rw-r--r--launcher/updater/DownloadTask.h9
-rw-r--r--launcher/updater/GoUpdate.cpp2
-rw-r--r--launcher/updater/GoUpdate.h2
-rw-r--r--launcher/updater/UpdateChecker.cpp38
-rw-r--r--launcher/updater/UpdateChecker.h8
-rw-r--r--launcher/updater/UpdateChecker_test.cpp6
7 files changed, 46 insertions, 33 deletions
diff --git a/launcher/updater/DownloadTask.cpp b/launcher/updater/DownloadTask.cpp
index 875d9d84..eba59142 100644
--- a/launcher/updater/DownloadTask.cpp
+++ b/launcher/updater/DownloadTask.cpp
@@ -26,8 +26,12 @@
namespace GoUpdate
{
-DownloadTask::DownloadTask(Status status, QString target, QObject *parent)
- : Task(parent), m_updateFilesDir(target)
+DownloadTask::DownloadTask(
+ shared_qobject_ptr<QNetworkAccessManager> network,
+ Status status,
+ QString target,
+ QObject *parent
+) : Task(parent), m_updateFilesDir(target), m_network(network)
{
m_status = status;
@@ -63,7 +67,7 @@ void DownloadTask::loadVersionInfo()
connect(netJob, &NetJob::succeeded, this, &DownloadTask::processDownloadedVersionInfo);
connect(netJob, &NetJob::failed, this, &DownloadTask::vinfoDownloadFailed);
m_vinfoNetJob.reset(netJob);
- netJob->start();
+ netJob->start(m_network);
}
void DownloadTask::vinfoDownloadFailed()
@@ -117,7 +121,7 @@ void DownloadTask::processDownloadedVersionInfo()
setStatus(tr("Processing file lists - figuring out how to install the update..."));
// make a new netjob for the actual update files
- NetJobPtr netJob (new NetJob("Update Files"));
+ NetJob::Ptr netJob (new NetJob("Update Files"));
// fill netJob and operationList
if (!processFileLists(m_currentVersionFileList, m_newVersionFileList, m_status.rootPath, m_updateFilesDir.path(), netJob, m_operations))
@@ -141,7 +145,7 @@ void DownloadTask::processDownloadedVersionInfo()
}
qDebug() << "Begin downloading update files to" << m_updateFilesDir.path();
m_filesNetJob = netJob;
- m_filesNetJob->start();
+ m_filesNetJob->start(m_network);
}
void DownloadTask::fileDownloadFinished()
diff --git a/launcher/updater/DownloadTask.h b/launcher/updater/DownloadTask.h
index fc5030b4..eac26238 100644
--- a/launcher/updater/DownloadTask.h
+++ b/launcher/updater/DownloadTask.h
@@ -35,7 +35,7 @@ public:
*
* target is a template - XXXXXX at the end will be replaced with a random generated string, ensuring uniqueness
*/
- explicit DownloadTask(Status status, QString target, QObject* parent = 0);
+ explicit DownloadTask(shared_qobject_ptr<QNetworkAccessManager> network, Status status, QString target, QObject* parent = 0);
virtual ~DownloadTask() {};
/// Get the directory that will contain the update files.
@@ -62,13 +62,13 @@ protected:
*/
void loadVersionInfo();
- NetJobPtr m_vinfoNetJob;
+ NetJob::Ptr m_vinfoNetJob;
QByteArray currentVersionFileListData;
QByteArray newVersionFileListData;
Net::Download::Ptr m_currentVersionFileListDownload;
Net::Download::Ptr m_newVersionFileListDownload;
- NetJobPtr m_filesNetJob;
+ NetJob::Ptr m_filesNetJob;
Status m_status;
@@ -91,6 +91,9 @@ protected slots:
void fileDownloadFinished();
void fileDownloadFailed(QString reason);
void fileDownloadProgressChanged(qint64 current, qint64 total);
+
+private:
+ shared_qobject_ptr<QNetworkAccessManager> m_network;
};
}
diff --git a/launcher/updater/GoUpdate.cpp b/launcher/updater/GoUpdate.cpp
index 6167418e..76f68b55 100644
--- a/launcher/updater/GoUpdate.cpp
+++ b/launcher/updater/GoUpdate.cpp
@@ -68,7 +68,7 @@ bool processFileLists
const VersionFileList &newVersion,
const QString &rootPath,
const QString &tempPath,
- NetJobPtr job,
+ NetJob::Ptr job,
OperationList &ops
)
{
diff --git a/launcher/updater/GoUpdate.h b/launcher/updater/GoUpdate.h
index 8058e543..46a679ef 100644
--- a/launcher/updater/GoUpdate.h
+++ b/launcher/updater/GoUpdate.h
@@ -117,7 +117,7 @@ bool processFileLists
const VersionFileList &newVersion,
const QString &rootPath,
const QString &tempPath,
- NetJobPtr job,
+ NetJob::Ptr job,
OperationList &ops
);
diff --git a/launcher/updater/UpdateChecker.cpp b/launcher/updater/UpdateChecker.cpp
index c96a6c9f..c72bbe0b 100644
--- a/launcher/updater/UpdateChecker.cpp
+++ b/launcher/updater/UpdateChecker.cpp
@@ -26,8 +26,9 @@
#include "BuildConfig.h"
#include "sys.h"
-UpdateChecker::UpdateChecker(QString channelUrl, QString currentChannel, int currentBuild)
+UpdateChecker::UpdateChecker(shared_qobject_ptr<QNetworkAccessManager> nam, QString channelUrl, QString currentChannel, int currentBuild)
{
+ m_network = nam;
m_channelUrl = channelUrl;
m_currentChannel = currentChannel;
m_currentBuild = currentBuild;
@@ -103,12 +104,11 @@ void UpdateChecker::checkForUpdate(QString updateChannel, bool notifyNoUpdate)
QUrl indexUrl = QUrl(m_newRepoUrl).resolved(QUrl("index.json"));
- auto job = new NetJob("GoUpdate Repository Index");
- job->addNetAction(Net::Download::makeByteArray(indexUrl, &indexData));
- connect(job, &NetJob::succeeded, [this, notifyNoUpdate](){ updateCheckFinished(notifyNoUpdate); });
- connect(job, &NetJob::failed, this, &UpdateChecker::updateCheckFailed);
- indexJob.reset(job);
- job->start();
+ indexJob = new NetJob("GoUpdate Repository Index");
+ indexJob->addNetAction(Net::Download::makeByteArray(indexUrl, &indexData));
+ connect(indexJob.get(), &NetJob::succeeded, [this, notifyNoUpdate](){ updateCheckFinished(notifyNoUpdate); });
+ connect(indexJob.get(), &NetJob::failed, this, &UpdateChecker::updateCheckFailed);
+ indexJob->start(m_network);
}
void UpdateChecker::updateCheckFinished(bool notifyNoUpdate)
@@ -191,12 +191,11 @@ void UpdateChecker::updateChanList(bool notifyNoUpdate)
}
m_chanListLoading = true;
- NetJob *job = new NetJob("Update System Channel List");
- job->addNetAction(Net::Download::makeByteArray(QUrl(m_channelUrl), &chanlistData));
- connect(job, &NetJob::succeeded, [this, notifyNoUpdate]() { chanListDownloadFinished(notifyNoUpdate); });
- QObject::connect(job, &NetJob::failed, this, &UpdateChecker::chanListDownloadFailed);
- chanListJob.reset(job);
- job->start();
+ chanListJob = new NetJob("Update System Channel List");
+ chanListJob->addNetAction(Net::Download::makeByteArray(QUrl(m_channelUrl), &chanlistData));
+ connect(chanListJob.get(), &NetJob::succeeded, [this, notifyNoUpdate]() { chanListDownloadFinished(notifyNoUpdate); });
+ connect(chanListJob.get(), &NetJob::failed, this, &UpdateChecker::chanListDownloadFailed);
+ chanListJob->start(m_network);
}
void UpdateChecker::chanListDownloadFinished(bool notifyNoUpdate)
@@ -233,10 +232,12 @@ void UpdateChecker::chanListDownloadFinished(bool notifyNoUpdate)
for (QJsonValue chanVal : channelArray)
{
QJsonObject channelObj = chanVal.toObject();
- ChannelListEntry entry{channelObj.value("id").toVariant().toString(),
- channelObj.value("name").toVariant().toString(),
- channelObj.value("description").toVariant().toString(),
- channelObj.value("url").toVariant().toString()};
+ ChannelListEntry entry {
+ channelObj.value("id").toVariant().toString(),
+ channelObj.value("name").toVariant().toString(),
+ channelObj.value("description").toVariant().toString(),
+ channelObj.value("url").toVariant().toString()
+ };
if (entry.id.isEmpty() || entry.name.isEmpty() || entry.url.isEmpty())
{
qCritical() << "Channel list entry with empty ID, name, or URL. Skipping.";
@@ -253,8 +254,9 @@ void UpdateChecker::chanListDownloadFinished(bool notifyNoUpdate)
qDebug() << "Successfully loaded UpdateChecker channel list.";
// If we're waiting to check for updates, do that now.
- if (m_checkUpdateWaiting)
+ if (m_checkUpdateWaiting) {
checkForUpdate(m_deferredUpdateChannel, notifyNoUpdate);
+ }
emit channelListLoaded();
}
diff --git a/launcher/updater/UpdateChecker.h b/launcher/updater/UpdateChecker.h
index 219c3c62..13ee4efd 100644
--- a/launcher/updater/UpdateChecker.h
+++ b/launcher/updater/UpdateChecker.h
@@ -23,7 +23,7 @@ class UpdateChecker : public QObject
Q_OBJECT
public:
- UpdateChecker(QString channelUrl, QString currentChannel, int currentBuild);
+ UpdateChecker(shared_qobject_ptr<QNetworkAccessManager> nam, QString channelUrl, QString currentChannel, int currentBuild);
void checkForUpdate(QString updateChannel, bool notifyNoUpdate);
/*!
@@ -73,9 +73,11 @@ private slots:
private:
friend class UpdateCheckerTest;
- NetJobPtr indexJob;
+ shared_qobject_ptr<QNetworkAccessManager> m_network;
+
+ NetJob::Ptr indexJob;
QByteArray indexData;
- NetJobPtr chanListJob;
+ NetJob::Ptr chanListJob;
QByteArray chanlistData;
QString m_channelUrl;
diff --git a/launcher/updater/UpdateChecker_test.cpp b/launcher/updater/UpdateChecker_test.cpp
index 5702d9c6..ec55a40e 100644
--- a/launcher/updater/UpdateChecker_test.cpp
+++ b/launcher/updater/UpdateChecker_test.cpp
@@ -91,7 +91,8 @@ slots:
QFETCH(bool, valid);
QFETCH(QList<UpdateChecker::ChannelListEntry>, result);
- UpdateChecker checker(channelUrl, channel, 0);
+ shared_qobject_ptr<QNetworkAccessManager> nam = new QNetworkAccessManager();
+ UpdateChecker checker(nam, channelUrl, channel, 0);
QSignalSpy channelListLoadedSpy(&checker, SIGNAL(channelListLoaded()));
QVERIFY(channelListLoadedSpy.isValid());
@@ -119,7 +120,8 @@ slots:
QString channelUrl = findTestDataUrl("data/channels.json");
int currentBuild = 2;
- UpdateChecker checker(channelUrl, channel, currentBuild);
+ shared_qobject_ptr<QNetworkAccessManager> nam = new QNetworkAccessManager();
+ UpdateChecker checker(nam, channelUrl, channel, currentBuild);
QSignalSpy updateAvailableSpy(&checker, SIGNAL(updateAvailable(GoUpdate::Status)));
QVERIFY(updateAvailableSpy.isValid());