mirror of
https://github.com/redstrate/Astra.git
synced 2025-04-20 19:57:45 +00:00
Re-arrange LauncherCore functions
This commit is contained in:
parent
0df05c79ad
commit
45cba2c0b6
2 changed files with 157 additions and 163 deletions
|
@ -71,11 +71,6 @@ class LauncherCore : public QObject
|
||||||
public:
|
public:
|
||||||
LauncherCore();
|
LauncherCore();
|
||||||
|
|
||||||
QNetworkAccessManager *mgr();
|
|
||||||
LauncherSettings *settings();
|
|
||||||
ProfileManager *profileManager();
|
|
||||||
AccountManager *accountManager();
|
|
||||||
|
|
||||||
/// Initializes the Steamworks API.
|
/// Initializes the Steamworks API.
|
||||||
void initializeSteam();
|
void initializeSteam();
|
||||||
|
|
||||||
|
@ -89,29 +84,34 @@ public:
|
||||||
/// check the result to see whether they need to "reset" or show a failed state or not. \note The login process is asynchronous.
|
/// check the result to see whether they need to "reset" or show a failed state or not. \note The login process is asynchronous.
|
||||||
Q_INVOKABLE bool autoLogin(Profile *profile);
|
Q_INVOKABLE bool autoLogin(Profile *profile);
|
||||||
|
|
||||||
|
Q_INVOKABLE GameInstaller *createInstaller(Profile *profile);
|
||||||
|
Q_INVOKABLE CompatibilityToolInstaller *createCompatInstaller();
|
||||||
|
|
||||||
|
Q_INVOKABLE void clearAvatarCache();
|
||||||
|
Q_INVOKABLE void refreshNews();
|
||||||
|
|
||||||
|
[[nodiscard]] Profile *currentProfile() const;
|
||||||
|
void setCurrentProfile(Profile *profile);
|
||||||
|
|
||||||
|
[[nodiscard]] QString autoLoginProfileName() const;
|
||||||
|
[[nodiscard]] Profile *autoLoginProfile() const;
|
||||||
|
void setAutoLoginProfile(Profile *value);
|
||||||
|
|
||||||
|
// Networking misc.
|
||||||
void buildRequest(const Profile &settings, QNetworkRequest &request);
|
void buildRequest(const Profile &settings, QNetworkRequest &request);
|
||||||
void setSSL(QNetworkRequest &request);
|
void setSSL(QNetworkRequest &request);
|
||||||
void setupIgnoreSSL(QNetworkReply *reply);
|
void setupIgnoreSSL(QNetworkReply *reply);
|
||||||
|
|
||||||
Q_INVOKABLE GameInstaller *createInstaller(Profile *profile);
|
|
||||||
Q_INVOKABLE CompatibilityToolInstaller *createCompatInstaller();
|
|
||||||
|
|
||||||
[[nodiscard]] bool isLoadingFinished() const;
|
[[nodiscard]] bool isLoadingFinished() const;
|
||||||
[[nodiscard]] bool isSteam() const;
|
[[nodiscard]] bool isSteam() const;
|
||||||
[[nodiscard]] bool isSteamDeck() const;
|
[[nodiscard]] bool isSteamDeck() const;
|
||||||
|
|
||||||
Q_INVOKABLE void refreshNews();
|
[[nodiscard]] QNetworkAccessManager *mgr();
|
||||||
|
[[nodiscard]] LauncherSettings *settings();
|
||||||
|
[[nodiscard]] ProfileManager *profileManager();
|
||||||
|
[[nodiscard]] AccountManager *accountManager();
|
||||||
[[nodiscard]] Headline *headline() const;
|
[[nodiscard]] Headline *headline() const;
|
||||||
|
|
||||||
[[nodiscard]] Profile *currentProfile() const;
|
|
||||||
void setCurrentProfile(Profile *profile);
|
|
||||||
|
|
||||||
Q_INVOKABLE void clearAvatarCache();
|
|
||||||
|
|
||||||
[[nodiscard]] QString autoLoginProfileName() const;
|
|
||||||
[[nodiscard]] Profile *autoLoginProfile() const;
|
|
||||||
void setAutoLoginProfile(Profile *value);
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void loadingFinished();
|
void loadingFinished();
|
||||||
void successfulLaunch();
|
void successfulLaunch();
|
||||||
|
@ -126,8 +126,6 @@ signals:
|
||||||
void autoLoginProfileChanged();
|
void autoLoginProfileChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void readInitialInformation();
|
|
||||||
|
|
||||||
QCoro::Task<> beginLogin(LoginInformation &info);
|
QCoro::Task<> beginLogin(LoginInformation &info);
|
||||||
|
|
||||||
QCoro::Task<> fetchNews();
|
QCoro::Task<> fetchNews();
|
||||||
|
|
|
@ -20,72 +20,17 @@
|
||||||
#include "squareenixlogin.h"
|
#include "squareenixlogin.h"
|
||||||
#include "utility.h"
|
#include "utility.h"
|
||||||
|
|
||||||
void LauncherCore::setSSL(QNetworkRequest &request)
|
LauncherCore::LauncherCore()
|
||||||
|
: QObject()
|
||||||
{
|
{
|
||||||
QSslConfiguration config;
|
m_settings = new LauncherSettings(this);
|
||||||
config.setProtocol(QSsl::AnyProtocol);
|
m_mgr = new QNetworkAccessManager(this);
|
||||||
config.setPeerVerifyMode(QSslSocket::VerifyNone);
|
m_sapphireLogin = new SapphireLogin(*this, this);
|
||||||
|
m_squareEnixLogin = new SquareEnixLogin(*this, this);
|
||||||
|
m_profileManager = new ProfileManager(*this, this);
|
||||||
|
m_accountManager = new AccountManager(*this, this);
|
||||||
|
m_runner = new GameRunner(*this, this);
|
||||||
|
|
||||||
request.setSslConfiguration(config);
|
|
||||||
}
|
|
||||||
|
|
||||||
void LauncherCore::setupIgnoreSSL(QNetworkReply *reply)
|
|
||||||
{
|
|
||||||
Q_ASSERT(reply != nullptr);
|
|
||||||
|
|
||||||
if (m_settings->preferredProtocol() == QStringLiteral("http")) {
|
|
||||||
connect(reply, &QNetworkReply::sslErrors, this, [reply](const QList<QSslError> &errors) {
|
|
||||||
reply->ignoreSslErrors(errors);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void LauncherCore::buildRequest(const Profile &settings, QNetworkRequest &request)
|
|
||||||
{
|
|
||||||
setSSL(request);
|
|
||||||
|
|
||||||
if (settings.account()->license() == Account::GameLicense::macOS) {
|
|
||||||
request.setHeader(QNetworkRequest::UserAgentHeader, QByteArrayLiteral("macSQEXAuthor/2.0.0(MacOSX; ja-jp)"));
|
|
||||||
} else {
|
|
||||||
request.setHeader(QNetworkRequest::UserAgentHeader, QStringLiteral("SQEXAuthor/2.0.0(Windows 6.2; ja-jp; %1)").arg(QString(QSysInfo::bootUniqueId())));
|
|
||||||
}
|
|
||||||
|
|
||||||
request.setRawHeader(QByteArrayLiteral("Accept"),
|
|
||||||
QByteArrayLiteral("image/gif, image/jpeg, image/pjpeg, application/x-ms-application, application/xaml+xml, "
|
|
||||||
"application/x-ms-xbap, */*"));
|
|
||||||
request.setRawHeader(QByteArrayLiteral("Accept-Encoding"), QByteArrayLiteral("gzip, deflate"));
|
|
||||||
request.setRawHeader(QByteArrayLiteral("Accept-Language"), QByteArrayLiteral("en-us"));
|
|
||||||
}
|
|
||||||
|
|
||||||
QCoro::Task<> LauncherCore::beginLogin(LoginInformation &info)
|
|
||||||
{
|
|
||||||
info.profile->account()->updateConfig();
|
|
||||||
|
|
||||||
auto assetUpdater = new AssetUpdater(*info.profile, *this, this);
|
|
||||||
if (co_await assetUpdater->update()) {
|
|
||||||
std::optional<LoginAuth> auth;
|
|
||||||
if (info.profile->account()->isSapphire()) {
|
|
||||||
auth = co_await m_sapphireLogin->login(info.profile->account()->lobbyUrl(), info);
|
|
||||||
} else {
|
|
||||||
auth = co_await m_squareEnixLogin->login(&info);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (auth != std::nullopt) {
|
|
||||||
Q_EMIT stageChanged(i18n("Launching game..."));
|
|
||||||
|
|
||||||
if (isSteam()) {
|
|
||||||
m_steamApi->setLauncherMode(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
m_runner->beginGameExecutable(*info.profile, *auth);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
assetUpdater->deleteLater();
|
|
||||||
}
|
|
||||||
|
|
||||||
void LauncherCore::readInitialInformation()
|
|
||||||
{
|
|
||||||
m_profileManager->load();
|
m_profileManager->load();
|
||||||
m_accountManager->load();
|
m_accountManager->load();
|
||||||
|
|
||||||
|
@ -105,17 +50,10 @@ void LauncherCore::readInitialInformation()
|
||||||
Q_EMIT loadingFinished();
|
Q_EMIT loadingFinished();
|
||||||
}
|
}
|
||||||
|
|
||||||
LauncherCore::LauncherCore()
|
void LauncherCore::initializeSteam()
|
||||||
{
|
{
|
||||||
m_settings = new LauncherSettings(this);
|
m_steamApi = new SteamAPI(this);
|
||||||
m_mgr = new QNetworkAccessManager(this);
|
m_steamApi->setLauncherMode(true);
|
||||||
m_sapphireLogin = new SapphireLogin(*this, this);
|
|
||||||
m_squareEnixLogin = new SquareEnixLogin(*this, this);
|
|
||||||
m_profileManager = new ProfileManager(*this, this);
|
|
||||||
m_accountManager = new AccountManager(*this, this);
|
|
||||||
m_runner = new GameRunner(*this, this);
|
|
||||||
|
|
||||||
readInitialInformation();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LauncherCore::login(Profile *profile, const QString &username, const QString &password, const QString &oneTimePassword)
|
void LauncherCore::login(Profile *profile, const QString &username, const QString &password, const QString &oneTimePassword)
|
||||||
|
@ -169,19 +107,35 @@ CompatibilityToolInstaller *LauncherCore::createCompatInstaller()
|
||||||
return new CompatibilityToolInstaller(*this, this);
|
return new CompatibilityToolInstaller(*this, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LauncherCore::isLoadingFinished() const
|
void LauncherCore::clearAvatarCache()
|
||||||
{
|
{
|
||||||
return m_loadingFinished;
|
const auto cacheLocation = QStandardPaths::standardLocations(QStandardPaths::CacheLocation)[0] + QStringLiteral("/avatars");
|
||||||
|
if (QDir(cacheLocation).exists()) {
|
||||||
|
QDir(cacheLocation).removeRecursively();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ProfileManager *LauncherCore::profileManager()
|
void LauncherCore::refreshNews()
|
||||||
{
|
{
|
||||||
return m_profileManager;
|
fetchNews();
|
||||||
}
|
}
|
||||||
|
|
||||||
AccountManager *LauncherCore::accountManager()
|
Profile *LauncherCore::currentProfile() const
|
||||||
{
|
{
|
||||||
return m_accountManager;
|
return m_profileManager->getProfile(m_currentProfileIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
void LauncherCore::setCurrentProfile(Profile *profile)
|
||||||
|
{
|
||||||
|
Q_ASSERT(profile != nullptr);
|
||||||
|
|
||||||
|
const int newIndex = m_profileManager->getProfileIndex(profile->uuid());
|
||||||
|
if (newIndex != m_currentProfileIndex) {
|
||||||
|
m_currentProfileIndex = newIndex;
|
||||||
|
m_settings->config()->setCurrentProfile(profile->uuid());
|
||||||
|
m_settings->config()->save();
|
||||||
|
Q_EMIT currentProfileChanged();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] QString LauncherCore::autoLoginProfileName() const
|
[[nodiscard]] QString LauncherCore::autoLoginProfileName() const
|
||||||
|
@ -214,9 +168,112 @@ void LauncherCore::setAutoLoginProfile(Profile *profile)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LauncherCore::refreshNews()
|
void LauncherCore::buildRequest(const Profile &settings, QNetworkRequest &request)
|
||||||
{
|
{
|
||||||
fetchNews();
|
setSSL(request);
|
||||||
|
|
||||||
|
if (settings.account()->license() == Account::GameLicense::macOS) {
|
||||||
|
request.setHeader(QNetworkRequest::UserAgentHeader, QByteArrayLiteral("macSQEXAuthor/2.0.0(MacOSX; ja-jp)"));
|
||||||
|
} else {
|
||||||
|
request.setHeader(QNetworkRequest::UserAgentHeader, QStringLiteral("SQEXAuthor/2.0.0(Windows 6.2; ja-jp; %1)").arg(QString(QSysInfo::bootUniqueId())));
|
||||||
|
}
|
||||||
|
|
||||||
|
request.setRawHeader(QByteArrayLiteral("Accept"),
|
||||||
|
QByteArrayLiteral("image/gif, image/jpeg, image/pjpeg, application/x-ms-application, application/xaml+xml, "
|
||||||
|
"application/x-ms-xbap, */*"));
|
||||||
|
request.setRawHeader(QByteArrayLiteral("Accept-Encoding"), QByteArrayLiteral("gzip, deflate"));
|
||||||
|
request.setRawHeader(QByteArrayLiteral("Accept-Language"), QByteArrayLiteral("en-us"));
|
||||||
|
}
|
||||||
|
|
||||||
|
void LauncherCore::setSSL(QNetworkRequest &request)
|
||||||
|
{
|
||||||
|
QSslConfiguration config;
|
||||||
|
config.setProtocol(QSsl::AnyProtocol);
|
||||||
|
config.setPeerVerifyMode(QSslSocket::VerifyNone);
|
||||||
|
|
||||||
|
request.setSslConfiguration(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
void LauncherCore::setupIgnoreSSL(QNetworkReply *reply)
|
||||||
|
{
|
||||||
|
Q_ASSERT(reply != nullptr);
|
||||||
|
|
||||||
|
if (m_settings->preferredProtocol() == QStringLiteral("http")) {
|
||||||
|
connect(reply, &QNetworkReply::sslErrors, this, [reply](const QList<QSslError> &errors) {
|
||||||
|
reply->ignoreSslErrors(errors);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool LauncherCore::isLoadingFinished() const
|
||||||
|
{
|
||||||
|
return m_loadingFinished;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool LauncherCore::isSteam() const
|
||||||
|
{
|
||||||
|
return m_steamApi != nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool LauncherCore::isSteamDeck() const
|
||||||
|
{
|
||||||
|
if (m_steamApi != nullptr) {
|
||||||
|
return m_steamApi->isDeck();
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QNetworkAccessManager *LauncherCore::mgr()
|
||||||
|
{
|
||||||
|
return m_mgr;
|
||||||
|
}
|
||||||
|
|
||||||
|
LauncherSettings *LauncherCore::settings()
|
||||||
|
{
|
||||||
|
return m_settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
ProfileManager *LauncherCore::profileManager()
|
||||||
|
{
|
||||||
|
return m_profileManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
AccountManager *LauncherCore::accountManager()
|
||||||
|
{
|
||||||
|
return m_accountManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
Headline *LauncherCore::headline() const
|
||||||
|
{
|
||||||
|
return m_headline;
|
||||||
|
}
|
||||||
|
|
||||||
|
QCoro::Task<> LauncherCore::beginLogin(LoginInformation &info)
|
||||||
|
{
|
||||||
|
info.profile->account()->updateConfig();
|
||||||
|
|
||||||
|
auto assetUpdater = new AssetUpdater(*info.profile, *this, this);
|
||||||
|
if (co_await assetUpdater->update()) {
|
||||||
|
std::optional<LoginAuth> auth;
|
||||||
|
if (info.profile->account()->isSapphire()) {
|
||||||
|
auth = co_await m_sapphireLogin->login(info.profile->account()->lobbyUrl(), info);
|
||||||
|
} else {
|
||||||
|
auth = co_await m_squareEnixLogin->login(&info);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (auth != std::nullopt) {
|
||||||
|
Q_EMIT stageChanged(i18n("Launching game..."));
|
||||||
|
|
||||||
|
if (isSteam()) {
|
||||||
|
m_steamApi->setLauncherMode(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
m_runner->beginGameExecutable(*info.profile, *auth);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
assetUpdater->deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
QCoro::Task<> LauncherCore::fetchNews()
|
QCoro::Task<> LauncherCore::fetchNews()
|
||||||
|
@ -294,64 +351,3 @@ QCoro::Task<> LauncherCore::fetchNews()
|
||||||
m_headline = headline;
|
m_headline = headline;
|
||||||
Q_EMIT newsChanged();
|
Q_EMIT newsChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
Headline *LauncherCore::headline() const
|
|
||||||
{
|
|
||||||
return m_headline;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool LauncherCore::isSteam() const
|
|
||||||
{
|
|
||||||
return m_steamApi != nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool LauncherCore::isSteamDeck() const
|
|
||||||
{
|
|
||||||
if (m_steamApi != nullptr) {
|
|
||||||
return m_steamApi->isDeck();
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Profile *LauncherCore::currentProfile() const
|
|
||||||
{
|
|
||||||
return m_profileManager->getProfile(m_currentProfileIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
void LauncherCore::setCurrentProfile(Profile *profile)
|
|
||||||
{
|
|
||||||
Q_ASSERT(profile != nullptr);
|
|
||||||
|
|
||||||
const int newIndex = m_profileManager->getProfileIndex(profile->uuid());
|
|
||||||
if (newIndex != m_currentProfileIndex) {
|
|
||||||
m_currentProfileIndex = newIndex;
|
|
||||||
m_settings->config()->setCurrentProfile(profile->uuid());
|
|
||||||
m_settings->config()->save();
|
|
||||||
Q_EMIT currentProfileChanged();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void LauncherCore::clearAvatarCache()
|
|
||||||
{
|
|
||||||
const auto cacheLocation = QStandardPaths::standardLocations(QStandardPaths::CacheLocation)[0] + QStringLiteral("/avatars");
|
|
||||||
if (QDir(cacheLocation).exists()) {
|
|
||||||
QDir(cacheLocation).removeRecursively();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void LauncherCore::initializeSteam()
|
|
||||||
{
|
|
||||||
m_steamApi = new SteamAPI(this);
|
|
||||||
m_steamApi->setLauncherMode(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
LauncherSettings *LauncherCore::settings()
|
|
||||||
{
|
|
||||||
return m_settings;
|
|
||||||
}
|
|
||||||
|
|
||||||
QNetworkAccessManager *LauncherCore::mgr()
|
|
||||||
{
|
|
||||||
return m_mgr;
|
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue