1
Fork 0
mirror of https://github.com/redstrate/Astra.git synced 2025-04-21 20:27:45 +00:00
astra/launcher/src/squareboot.cpp

93 lines
3.1 KiB
C++
Raw Normal View History

// SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.com>
// SPDX-License-Identifier: GPL-3.0-or-later
2021-11-01 09:54:58 -04:00
#include "squareboot.h"
#include <KLocalizedString>
2022-08-15 11:14:37 -04:00
#include <QFile>
#include <QJsonDocument>
#include <QNetworkReply>
#include <QStandardPaths>
2022-08-15 11:14:37 -04:00
#include <QUrlQuery>
#include <physis.hpp>
#include <qcoronetworkreply.h>
2021-11-01 09:54:58 -04:00
#include "account.h"
2021-11-01 09:54:58 -04:00
#include "squarelauncher.h"
SquareBoot::SquareBoot(LauncherCore &window, SquareLauncher &launcher, QObject *parent)
: QObject(parent)
, window(window)
, launcher(launcher)
{
}
QCoro::Task<> SquareBoot::bootCheck(const LoginInformation &info)
{
Q_EMIT window.stageChanged(i18n("Checking for launcher updates..."));
qDebug() << "Performing boot check...";
2021-11-01 09:54:58 -04:00
const QUrlQuery query{{QStringLiteral("time"), QDateTime::currentDateTimeUtc().toString(QStringLiteral("yyyy-MM-dd-HH-mm"))}};
2021-11-01 09:54:58 -04:00
QUrl url;
url.setScheme(QStringLiteral("http"));
url.setHost(QStringLiteral("patch-bootver.%1").arg(window.squareEnixServer()));
2023-09-17 08:51:26 -04:00
url.setPath(QStringLiteral("/http/win32/ffxivneo_release_boot/%1").arg(info.profile->bootVersion()));
2021-11-01 09:54:58 -04:00
url.setQuery(query);
auto request = QNetworkRequest(url);
if (info.profile->account()->license() == Account::GameLicense::macOS) {
request.setRawHeader(QByteArrayLiteral("User-Agent"), QByteArrayLiteral("FFXIV-MAC PATCH CLIENT"));
} else {
request.setRawHeader(QByteArrayLiteral("User-Agent"), QByteArrayLiteral("FFXIV PATCH CLIENT"));
}
request.setRawHeader(QByteArrayLiteral("Host"), QStringLiteral("patch-bootver.%1").arg(window.squareEnixServer()).toUtf8());
2021-11-01 09:54:58 -04:00
const auto reply = window.mgr->get(request);
co_await reply;
const QString patchList = reply->readAll();
if (!patchList.isEmpty()) {
patcher = new Patcher(window, info.profile->gamePath() + QStringLiteral("/boot"), *info.profile->bootData(), this);
const bool hasPatched = co_await patcher->patch(PatchList(patchList));
if (hasPatched) {
// update game version information
info.profile->readGameVersion();
}
patcher->deleteLater();
}
2023-09-16 20:12:42 -04:00
launcher.login(info);
}
QCoro::Task<> SquareBoot::checkGateStatus(const LoginInformation &info)
{
Q_EMIT window.stageChanged(i18n("Checking gate..."));
qDebug() << "Checking gate...";
QUrl url;
url.setScheme(window.preferredProtocol());
url.setHost(QStringLiteral("frontier.%1").arg(window.squareEnixServer()));
url.setPath(QStringLiteral("/worldStatus/gate_status.json"));
2022-09-05 15:49:58 -04:00
url.setQuery(QString::number(QDateTime::currentMSecsSinceEpoch()));
2022-09-05 15:50:58 -04:00
QNetworkRequest request(url);
// TODO: really?
window.buildRequest(*info.profile, request);
const auto reply = window.mgr->get(request);
window.setupIgnoreSSL(reply);
co_await reply;
const QJsonDocument document = QJsonDocument::fromJson(reply->readAll());
const bool isGateOpen = !document.isEmpty() && document.object()[QLatin1String("status")].toInt() != 0;
if (isGateOpen) {
bootCheck(info);
} else {
Q_EMIT window.loginError(i18n("The login gate is closed, the game may be under maintenance.\n\n%1", reply->errorString()));
}
}