mirror of
https://github.com/redstrate/Astra.git
synced 2025-04-21 20:27:45 +00:00
Modernize bits of the Patcher class
This commit is contained in:
parent
72f3cf2052
commit
8e9d1587f0
4 changed files with 35 additions and 38 deletions
|
@ -17,18 +17,18 @@ class Patcher : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
Patcher(LauncherCore &launcher, QString baseDirectory, GameData *game_data, QObject *parent = nullptr);
|
Patcher(LauncherCore &launcher, const QString &baseDirectory, GameData &gameData, QObject *parent = nullptr);
|
||||||
Patcher(LauncherCore &launcher, QString baseDirectory, BootData *game_data, QObject *parent = nullptr);
|
Patcher(LauncherCore &launcher, const QString &baseDirectory, BootData &bootData, QObject *parent = nullptr);
|
||||||
|
|
||||||
QCoro::Task<> patch(QNetworkAccessManager &mgr, const QString &patchList);
|
QCoro::Task<> patch(const QString &patchList);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setupDirectories();
|
void setupDirectories();
|
||||||
QString getBaseString() const;
|
[[nodiscard]] QString getBaseString() const;
|
||||||
|
|
||||||
[[nodiscard]] bool isBoot() const
|
[[nodiscard]] bool isBoot() const
|
||||||
{
|
{
|
||||||
return boot_data != nullptr;
|
return m_bootData != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct QueuedPatch {
|
struct QueuedPatch {
|
||||||
|
@ -38,7 +38,7 @@ private:
|
||||||
long length;
|
long length;
|
||||||
bool isBoot;
|
bool isBoot;
|
||||||
|
|
||||||
QString getVersion() const
|
[[nodiscard]] QString getVersion() const
|
||||||
{
|
{
|
||||||
if (isBoot) {
|
if (isBoot) {
|
||||||
return QStringLiteral("ffxivboot - %1").arg(name);
|
return QStringLiteral("ffxivboot - %1").arg(name);
|
||||||
|
@ -50,14 +50,14 @@ private:
|
||||||
|
|
||||||
void processPatch(const QueuedPatch &patch);
|
void processPatch(const QueuedPatch &patch);
|
||||||
|
|
||||||
QVector<QueuedPatch> patchQueue;
|
QVector<QueuedPatch> m_patchQueue;
|
||||||
|
|
||||||
QDir patchesDir;
|
QDir m_patchesDir;
|
||||||
QString baseDirectory;
|
QString m_baseDirectory;
|
||||||
BootData *boot_data = nullptr;
|
BootData *m_bootData = nullptr;
|
||||||
GameData *game_data = nullptr;
|
GameData *m_gameData = nullptr;
|
||||||
|
|
||||||
int remainingPatches = -1;
|
int m_remainingPatches = -1;
|
||||||
|
|
||||||
LauncherCore &m_launcher;
|
LauncherCore &m_launcher;
|
||||||
};
|
};
|
||||||
|
|
|
@ -12,14 +12,13 @@
|
||||||
#include <QtConcurrent>
|
#include <QtConcurrent>
|
||||||
#include <physis.hpp>
|
#include <physis.hpp>
|
||||||
#include <qcorofuture.h>
|
#include <qcorofuture.h>
|
||||||
#include <utility>
|
|
||||||
|
|
||||||
#include "launchercore.h"
|
#include "launchercore.h"
|
||||||
|
|
||||||
Patcher::Patcher(LauncherCore &launcher, QString baseDirectory, BootData *boot_data, QObject *parent)
|
Patcher::Patcher(LauncherCore &launcher, const QString &baseDirectory, BootData &bootData, QObject *parent)
|
||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
, baseDirectory(std::move(baseDirectory))
|
, m_baseDirectory(baseDirectory)
|
||||||
, boot_data(boot_data)
|
, m_bootData(&bootData)
|
||||||
, m_launcher(launcher)
|
, m_launcher(launcher)
|
||||||
{
|
{
|
||||||
setupDirectories();
|
setupDirectories();
|
||||||
|
@ -27,10 +26,10 @@ Patcher::Patcher(LauncherCore &launcher, QString baseDirectory, BootData *boot_d
|
||||||
Q_EMIT m_launcher.stageChanged(i18n("Checking the FINAL FANTASY XIV Updater/Launcher version."));
|
Q_EMIT m_launcher.stageChanged(i18n("Checking the FINAL FANTASY XIV Updater/Launcher version."));
|
||||||
}
|
}
|
||||||
|
|
||||||
Patcher::Patcher(LauncherCore &launcher, QString baseDirectory, GameData *game_data, QObject *parent)
|
Patcher::Patcher(LauncherCore &launcher, const QString &baseDirectory, GameData &gameData, QObject *parent)
|
||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
, baseDirectory(std::move(baseDirectory))
|
, m_baseDirectory(baseDirectory)
|
||||||
, game_data(game_data)
|
, m_gameData(&gameData)
|
||||||
, m_launcher(launcher)
|
, m_launcher(launcher)
|
||||||
{
|
{
|
||||||
setupDirectories();
|
setupDirectories();
|
||||||
|
@ -38,7 +37,7 @@ Patcher::Patcher(LauncherCore &launcher, QString baseDirectory, GameData *game_d
|
||||||
Q_EMIT m_launcher.stageChanged(i18n("Checking the FINAL FANTASY XIV Game version."));
|
Q_EMIT m_launcher.stageChanged(i18n("Checking the FINAL FANTASY XIV Game version."));
|
||||||
}
|
}
|
||||||
|
|
||||||
QCoro::Task<> Patcher::patch(QNetworkAccessManager &mgr, const QString &patchList)
|
QCoro::Task<> Patcher::patch(const QString &patchList)
|
||||||
{
|
{
|
||||||
if (patchList.isEmpty()) {
|
if (patchList.isEmpty()) {
|
||||||
co_return;
|
co_return;
|
||||||
|
@ -49,8 +48,8 @@ QCoro::Task<> Patcher::patch(QNetworkAccessManager &mgr, const QString &patchLis
|
||||||
|
|
||||||
const QStringList parts = patchList.split("\r\n");
|
const QStringList parts = patchList.split("\r\n");
|
||||||
|
|
||||||
remainingPatches = parts.size() - 7;
|
m_remainingPatches = parts.size() - 7;
|
||||||
patchQueue.resize(remainingPatches);
|
m_patchQueue.resize(m_remainingPatches);
|
||||||
|
|
||||||
QFutureSynchronizer<void> synchronizer;
|
QFutureSynchronizer<void> synchronizer;
|
||||||
|
|
||||||
|
@ -73,7 +72,7 @@ QCoro::Task<> Patcher::patch(QNetworkAccessManager &mgr, const QString &patchLis
|
||||||
auto url_parts = url.split(QLatin1Char('/'));
|
auto url_parts = url.split(QLatin1Char('/'));
|
||||||
const QString repository = url_parts[url_parts.size() - 3];
|
const QString repository = url_parts[url_parts.size() - 3];
|
||||||
|
|
||||||
const QDir repositoryDir = patchesDir.absoluteFilePath(repository);
|
const QDir repositoryDir = m_patchesDir.absoluteFilePath(repository);
|
||||||
|
|
||||||
if (!QDir().exists(repositoryDir.absolutePath()))
|
if (!QDir().exists(repositoryDir.absolutePath()))
|
||||||
QDir().mkpath(repositoryDir.absolutePath());
|
QDir().mkpath(repositoryDir.absolutePath());
|
||||||
|
@ -82,12 +81,12 @@ QCoro::Task<> Patcher::patch(QNetworkAccessManager &mgr, const QString &patchLis
|
||||||
|
|
||||||
const QueuedPatch patch{name, repository, version, patchPath, hashes, hashBlockSize, length, isBoot()};
|
const QueuedPatch patch{name, repository, version, patchPath, hashes, hashBlockSize, length, isBoot()};
|
||||||
|
|
||||||
patchQueue[ourIndex] = patch;
|
m_patchQueue[ourIndex] = patch;
|
||||||
|
|
||||||
if (!QFile::exists(patchPath)) {
|
if (!QFile::exists(patchPath)) {
|
||||||
auto patchReply = mgr.get(QNetworkRequest(url));
|
auto patchReply = m_launcher.mgr->get(QNetworkRequest(url));
|
||||||
|
|
||||||
connect(patchReply, &QNetworkReply::downloadProgress, [this, patch](int received, int total) {
|
connect(patchReply, &QNetworkReply::downloadProgress, this, [this, patch](int received, int total) {
|
||||||
Q_EMIT m_launcher.stageChanged(i18n("Updating %1.\nDownloading %2", getBaseString(), patch.getVersion()));
|
Q_EMIT m_launcher.stageChanged(i18n("Updating %1.\nDownloading %2", getBaseString(), patch.getVersion()));
|
||||||
Q_EMIT m_launcher.stageDeterminate(0, total, received);
|
Q_EMIT m_launcher.stageDeterminate(0, total, received);
|
||||||
});
|
});
|
||||||
|
@ -109,14 +108,12 @@ QCoro::Task<> Patcher::patch(QNetworkAccessManager &mgr, const QString &patchLis
|
||||||
|
|
||||||
// This must happen synchronously
|
// This must happen synchronously
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
for (const auto &patch : patchQueue) {
|
for (const auto &patch : m_patchQueue) {
|
||||||
Q_EMIT m_launcher.stageChanged(i18n("Updating %1.\nInstalling %2", getBaseString(), patch.getVersion()));
|
Q_EMIT m_launcher.stageChanged(i18n("Updating %1.\nInstalling %2", getBaseString(), patch.getVersion()));
|
||||||
Q_EMIT m_launcher.stageDeterminate(0, patchQueue.size(), i++);
|
Q_EMIT m_launcher.stageDeterminate(0, m_patchQueue.size(), i++);
|
||||||
|
|
||||||
processPatch(patch);
|
processPatch(patch);
|
||||||
}
|
}
|
||||||
|
|
||||||
co_return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Patcher::processPatch(const QueuedPatch &patch)
|
void Patcher::processPatch(const QueuedPatch &patch)
|
||||||
|
@ -147,19 +144,19 @@ void Patcher::processPatch(const QueuedPatch &patch)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isBoot()) {
|
if (isBoot()) {
|
||||||
physis_bootdata_apply_patch(boot_data, patch.path.toStdString().c_str());
|
physis_bootdata_apply_patch(m_bootData, patch.path.toStdString().c_str());
|
||||||
} else {
|
} else {
|
||||||
physis_gamedata_apply_patch(game_data, patch.path.toStdString().c_str());
|
physis_gamedata_apply_patch(m_gameData, patch.path.toStdString().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
QString verFilePath;
|
QString verFilePath;
|
||||||
if (isBoot()) {
|
if (isBoot()) {
|
||||||
verFilePath = baseDirectory + QStringLiteral("/ffxivboot.ver");
|
verFilePath = m_baseDirectory + QStringLiteral("/ffxivboot.ver");
|
||||||
} else {
|
} else {
|
||||||
if (patch.repository == QLatin1String("game")) {
|
if (patch.repository == QLatin1String("game")) {
|
||||||
verFilePath = baseDirectory + QStringLiteral("/ffxivgame.ver");
|
verFilePath = m_baseDirectory + QStringLiteral("/ffxivgame.ver");
|
||||||
} else {
|
} else {
|
||||||
verFilePath = baseDirectory + QStringLiteral("/sqpack/") + patch.repository + QStringLiteral("/") + patch.repository + QStringLiteral(".ver");
|
verFilePath = m_baseDirectory + QStringLiteral("/sqpack/") + patch.repository + QStringLiteral("/") + patch.repository + QStringLiteral(".ver");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -178,7 +175,7 @@ void Patcher::setupDirectories()
|
||||||
dataDir.setPath(QStandardPaths::writableLocation(QStandardPaths::TempLocation));
|
dataDir.setPath(QStandardPaths::writableLocation(QStandardPaths::TempLocation));
|
||||||
}
|
}
|
||||||
|
|
||||||
patchesDir.setPath(dataDir.absoluteFilePath(QStringLiteral("patches")));
|
m_patchesDir.setPath(dataDir.absoluteFilePath(QStringLiteral("patches")));
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Patcher::getBaseString() const
|
QString Patcher::getBaseString() const
|
||||||
|
|
|
@ -48,7 +48,7 @@ QCoro::Task<> SquareBoot::bootCheck(const LoginInformation &info)
|
||||||
co_await reply;
|
co_await reply;
|
||||||
|
|
||||||
patcher = new Patcher(window, info.profile->gamePath() + QStringLiteral("/boot"), info.profile->bootData, this);
|
patcher = new Patcher(window, info.profile->gamePath() + QStringLiteral("/boot"), info.profile->bootData, this);
|
||||||
co_await patcher->patch(*window.mgr, reply->readAll());
|
co_await patcher->patch(reply->readAll());
|
||||||
|
|
||||||
// update game version information
|
// update game version information
|
||||||
info.profile->readGameVersion();
|
info.profile->readGameVersion();
|
||||||
|
|
|
@ -185,7 +185,7 @@ QCoro::Task<> SquareLauncher::registerSession(const LoginInformation &info)
|
||||||
const QString body = reply->readAll();
|
const QString body = reply->readAll();
|
||||||
|
|
||||||
patcher = new Patcher(window, info.profile->gamePath() + QStringLiteral("/game"), info.profile->gameData, this);
|
patcher = new Patcher(window, info.profile->gamePath() + QStringLiteral("/game"), info.profile->gameData, this);
|
||||||
co_await patcher->patch(*window.mgr, body);
|
co_await patcher->patch(body);
|
||||||
|
|
||||||
info.profile->readGameVersion();
|
info.profile->readGameVersion();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue