1
Fork 0
mirror of https://github.com/redstrate/Astra.git synced 2025-04-20 11:47:46 +00:00
astra/launcher/include/launchercore.h

158 lines
4.7 KiB
C
Raw Normal View History

// SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.com>
// SPDX-License-Identifier: GPL-3.0-or-later
#pragma once
#include <QFuture>
#include <QNetworkAccessManager>
#include <QProcess>
#include <QtQml>
2023-09-16 18:37:42 -04:00
#include <qcorotask.h>
#include "accountmanager.h"
#include "headline.h"
#include "launchersettings.h"
#include "profile.h"
#include "profilemanager.h"
#include "steamapi.h"
class SapphireLogin;
class SquareEnixLogin;
class AssetUpdater;
class GameInstaller;
class CompatibilityToolInstaller;
class GameRunner;
class LoginInformation : public QObject
{
Q_OBJECT
Q_PROPERTY(QString username MEMBER username)
Q_PROPERTY(QString password MEMBER password)
Q_PROPERTY(QString oneTimePassword MEMBER oneTimePassword)
Q_PROPERTY(Profile *profile MEMBER profile)
public:
2023-09-17 08:31:24 -04:00
explicit LoginInformation(QObject *parent = nullptr)
2023-07-30 10:11:14 -04:00
: QObject(parent)
{
}
Profile *profile = nullptr;
QString username, password, oneTimePassword;
};
struct LoginAuth {
QString SID;
int region = 2; // america?
int maxExpansion = 1;
// if empty, don't set on the client
QString lobbyhost, frontierHost;
};
class LauncherCore : public QObject
{
Q_OBJECT
2023-09-16 18:01:02 -04:00
QML_ELEMENT
QML_SINGLETON
Q_PROPERTY(bool loadingFinished READ isLoadingFinished NOTIFY loadingFinished)
Q_PROPERTY(bool isSteam READ isSteam CONSTANT)
Q_PROPERTY(bool isSteamDeck READ isSteamDeck CONSTANT)
Q_PROPERTY(LauncherSettings *settings READ settings CONSTANT)
Q_PROPERTY(ProfileManager *profileManager READ profileManager CONSTANT)
Q_PROPERTY(AccountManager *accountManager READ accountManager CONSTANT)
Q_PROPERTY(Headline *headline READ headline NOTIFY newsChanged)
Q_PROPERTY(Profile *currentProfile READ currentProfile WRITE setCurrentProfile NOTIFY currentProfileChanged)
2023-09-17 19:20:41 -04:00
Q_PROPERTY(Profile *autoLoginProfile READ autoLoginProfile WRITE setAutoLoginProfile NOTIFY autoLoginProfileChanged)
public:
2023-09-16 18:01:02 -04:00
LauncherCore();
QNetworkAccessManager *mgr();
LauncherSettings *settings();
ProfileManager *profileManager();
AccountManager *accountManager();
void initializeSteam();
2023-09-16 18:01:02 -04:00
/*
* Begins the login process, and may call SquareBoot or SapphireLauncher depending on the profile type.
* It's designed to be opaque as possible to the caller.
*
* The login process is asynchronous.
*/
Q_INVOKABLE void login(Profile *profile, const QString &username, const QString &password, const QString &oneTimePassword);
/*
* Attempts to log into a profile without LoginInformation, which may or may not work depending on a combination of
* the password failing, OTP not being available to auto-generate, among other things.
*
* The launcher will still warn the user about any possible errors, however the call site will need to check the
* result to see whether they need to "reset" or show a failed state or not.
*/
2023-10-08 13:21:13 -04:00
Q_INVOKABLE bool autoLogin(Profile *profile);
void buildRequest(const Profile &settings, QNetworkRequest &request);
void setSSL(QNetworkRequest &request);
void setupIgnoreSSL(QNetworkReply *reply);
Q_INVOKABLE GameInstaller *createInstaller(Profile *profile);
Q_INVOKABLE CompatibilityToolInstaller *createCompatInstaller();
2023-09-17 08:31:24 -04:00
[[nodiscard]] bool isLoadingFinished() const;
[[nodiscard]] bool isSteam() const;
[[nodiscard]] bool isSteamDeck() const;
Q_INVOKABLE void refreshNews();
2023-09-17 09:02:11 -04:00
[[nodiscard]] Headline *headline() const;
2023-09-17 08:31:24 -04:00
[[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:
void loadingFinished();
void successfulLaunch();
void gameClosed();
void loginError(QString message);
void dalamudError(QString message);
void stageChanged(QString message);
void stageIndeterminate();
void stageDeterminate(int min, int max, int value);
void newsChanged();
void currentProfileChanged();
2023-09-17 19:20:41 -04:00
void autoLoginProfileChanged();
private:
void readInitialInformation();
QCoro::Task<> beginLogin(LoginInformation &info);
2023-09-16 18:37:42 -04:00
QCoro::Task<> fetchNews();
2023-09-17 08:31:24 -04:00
SteamAPI *m_steamApi = nullptr;
bool m_loadingFinished = false;
ProfileManager *m_profileManager = nullptr;
AccountManager *m_accountManager = nullptr;
SapphireLogin *m_sapphireLogin = nullptr;
SquareEnixLogin *m_squareEnixLogin = nullptr;
2023-09-17 08:31:24 -04:00
QNetworkAccessManager *m_mgr = nullptr;
Headline *m_headline = nullptr;
LauncherSettings *m_settings = nullptr;
GameRunner *m_runner = nullptr;
int m_currentProfileIndex = 0;
};