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

91 lines
2.9 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>
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)
{
}
void 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
patcher = new Patcher(window, info.profile->gamePath() + "/boot", info.profile->bootData, this);
2023-07-30 10:11:14 -04:00
connect(patcher, &Patcher::done, [this, &info] {
info.profile->readGameVersion();
launcher.getStored(info);
});
2021-11-01 09:54:58 -04:00
QUrlQuery query;
query.addQueryItem("time", QDateTime::currentDateTimeUtc().toString("yyyy-MM-dd-HH-mm"));
QUrl url;
url.setScheme("http");
url.setHost(QStringLiteral("patch-bootver.%1").arg(window.squareEnixServer()));
url.setPath(QString("/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("User-Agent", "FFXIV-MAC PATCH CLIENT");
} else {
request.setRawHeader("User-Agent", "FFXIV PATCH CLIENT");
}
request.setRawHeader("Host", QStringLiteral("patch-bootver.%1").arg(window.squareEnixServer()).toUtf8());
2021-11-01 09:54:58 -04:00
auto reply = window.mgr->get(request);
connect(reply, &QNetworkReply::finished, [this, reply] {
const QString response = reply->readAll();
patcher->processPatchList(*window.mgr, response);
2021-11-01 09:54:58 -04:00
});
}
void SquareBoot::checkGateStatus(LoginInformation *info)
{
Q_EMIT window.stageChanged(i18n("Checking gate..."));
qDebug() << "Checking gate...";
QUrl url;
url.setScheme("https");
url.setHost(QStringLiteral("frontier.%1").arg(window.squareEnixServer()));
url.setPath("/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);
auto reply = window.mgr->get(request);
2023-07-30 10:11:14 -04:00
connect(reply, &QNetworkReply::finished, [this, reply, info] {
2023-08-18 22:03:07 -04:00
const QJsonDocument document = QJsonDocument::fromJson(reply->readAll());
const bool isGateOpen = !document.isEmpty() && document.object()["status"].toInt() != 0;
2022-08-15 11:14:37 -04:00
if (isGateOpen) {
bootCheck(*info);
} else {
2023-08-18 22:03:07 -04:00
Q_EMIT window.loginError(i18n("The login gate is closed, the game may be under maintenance.\n\n%1", reply->errorString()));
}
});
}