2023-08-05 22:14:05 -04:00
// SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.com>
// SPDX-License-Identifier: GPL-3.0-or-later
2023-07-30 08:49:34 -04:00
# pragma once
# include <QNetworkAccessManager>
# include <QtQml>
2023-09-16 18:37:42 -04:00
# include <qcorotask.h>
2023-07-30 08:49:34 -04:00
# include "accountmanager.h"
# include "headline.h"
2023-10-11 13:25:24 -04:00
# include "launchersettings.h"
2023-07-30 08:49:34 -04:00
# include "profile.h"
# include "profilemanager.h"
# include "steamapi.h"
2023-10-11 14:13:42 -04:00
class SapphireLogin ;
class SquareEnixLogin ;
2023-07-30 08:49:34 -04:00
class AssetUpdater ;
class GameInstaller ;
2023-08-18 23:27:29 -04:00
class CompatibilityToolInstaller ;
2023-10-11 14:30:21 -04:00
class GameRunner ;
2024-04-19 20:29:28 -04:00
class BenchmarkInstaller ;
2024-07-28 11:17:30 -04:00
class SyncManager ;
2023-07-30 08:49:34 -04:00
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 )
{
}
2023-07-30 08:49:34 -04:00
Profile * profile = nullptr ;
QString username , password , oneTimePassword ;
} ;
struct LoginAuth {
QString SID ;
int region = 2 ; // america?
int maxExpansion = 1 ;
2023-10-08 13:19:23 -04:00
// if empty, don't set on the client
2023-07-30 08:49:34 -04:00
QString lobbyhost , frontierHost ;
} ;
class LauncherCore : public QObject
{
Q_OBJECT
2023-09-16 18:01:02 -04:00
QML_ELEMENT
QML_SINGLETON
2023-07-30 08:49:34 -04:00
Q_PROPERTY ( bool loadingFinished READ isLoadingFinished NOTIFY loadingFinished )
Q_PROPERTY ( bool isSteam READ isSteam CONSTANT )
2023-07-31 18:58:02 -04:00
Q_PROPERTY ( bool isSteamDeck READ isSteamDeck CONSTANT )
2024-04-27 16:38:22 +00:00
Q_PROPERTY ( bool isWindows READ isWindows CONSTANT )
2023-10-11 13:25:24 -04:00
Q_PROPERTY ( LauncherSettings * settings READ settings CONSTANT )
2023-07-30 08:49:34 -04:00
Q_PROPERTY ( ProfileManager * profileManager READ profileManager CONSTANT )
Q_PROPERTY ( AccountManager * accountManager READ accountManager CONSTANT )
Q_PROPERTY ( Headline * headline READ headline NOTIFY newsChanged )
2023-09-16 20:12:01 -04:00
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 )
2024-07-30 18:43:06 -04:00
# ifdef BUILD_SYNC
2024-07-28 11:17:30 -04:00
Q_PROPERTY ( SyncManager * syncManager READ syncManager CONSTANT )
2024-07-30 18:43:06 -04:00
# endif
2023-07-30 08:49:34 -04:00
public :
2023-09-16 18:01:02 -04:00
LauncherCore ( ) ;
2023-07-30 08:49:34 -04:00
2023-10-11 14:40:56 -04:00
/// Initializes the Steamworks API.
2023-10-08 17:55:13 -04:00
void initializeSteam ( ) ;
2023-09-16 18:01:02 -04:00
2023-10-11 14:40:56 -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.
/// \note The login process is asynchronous.
2023-07-30 08:49:34 -04:00
Q_INVOKABLE void login ( Profile * profile , const QString & username , const QString & password , const QString & oneTimePassword ) ;
2023-10-11 14:40:56 -04:00
/// 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. \note The login process is asynchronous.
2023-10-08 13:21:13 -04:00
Q_INVOKABLE bool autoLogin ( Profile * profile ) ;
2023-07-30 08:49:34 -04:00
2024-06-27 16:38:45 -04:00
/// Launches the game without patching, or logging in.
/// Meant to test if we can get to the title screen and is intended to fail to do anything else.
Q_INVOKABLE void immediatelyLaunch ( Profile * profile ) ;
2023-08-18 12:59:07 -04:00
Q_INVOKABLE GameInstaller * createInstaller ( Profile * profile ) ;
2024-04-01 14:54:41 -04:00
Q_INVOKABLE GameInstaller * createInstallerFromExisting ( Profile * profile , const QString & filePath ) ;
2023-08-18 23:27:29 -04:00
Q_INVOKABLE CompatibilityToolInstaller * createCompatInstaller ( ) ;
2024-04-19 20:29:28 -04:00
Q_INVOKABLE BenchmarkInstaller * createBenchmarkInstaller ( Profile * profile ) ;
Q_INVOKABLE BenchmarkInstaller * createBenchmarkInstallerFromExisting ( Profile * profile , const QString & filePath ) ;
2023-07-30 08:49:34 -04:00
2024-08-22 18:46:45 -04:00
/// Fetches the avatar for @p account
void fetchAvatar ( Account * account ) ;
2023-10-11 14:49:24 -04:00
Q_INVOKABLE void clearAvatarCache ( ) ;
2024-08-22 18:46:45 -04:00
2023-07-30 08:49:34 -04:00
Q_INVOKABLE void refreshNews ( ) ;
2024-03-22 20:12:06 -04:00
Q_INVOKABLE void refreshLogoImage ( ) ;
2023-07-30 08:49:34 -04:00
2023-09-17 08:31:24 -04:00
[ [ nodiscard ] ] Profile * currentProfile ( ) const ;
2024-07-04 20:53:06 -04:00
void setCurrentProfile ( const Profile * profile ) ;
2023-09-16 20:12:01 -04:00
2023-10-11 13:25:24 -04:00
[ [ nodiscard ] ] QString autoLoginProfileName ( ) const ;
[ [ nodiscard ] ] Profile * autoLoginProfile ( ) const ;
2024-07-04 20:53:06 -04:00
void setAutoLoginProfile ( const Profile * value ) ;
2023-10-11 13:25:24 -04:00
2023-10-11 14:49:24 -04:00
// Networking misc.
void buildRequest ( const Profile & settings , QNetworkRequest & request ) ;
void setupIgnoreSSL ( QNetworkReply * reply ) ;
[ [ nodiscard ] ] bool isLoadingFinished ( ) const ;
[ [ nodiscard ] ] bool isSteam ( ) const ;
[ [ nodiscard ] ] bool isSteamDeck ( ) const ;
2024-05-18 14:26:33 -04:00
[ [ nodiscard ] ] static bool isWindows ( ) ;
[ [ nodiscard ] ] static bool needsCompatibilityTool ( ) ;
2023-10-11 17:45:02 -04:00
[ [ nodiscard ] ] Q_INVOKABLE bool isPatching ( ) const ;
2024-07-30 18:43:06 -04:00
[ [ nodiscard ] ] Q_INVOKABLE bool supportsSync ( ) const ;
2023-10-11 14:49:24 -04:00
[ [ nodiscard ] ] QNetworkAccessManager * mgr ( ) ;
[ [ nodiscard ] ] LauncherSettings * settings ( ) ;
[ [ nodiscard ] ] ProfileManager * profileManager ( ) ;
[ [ nodiscard ] ] AccountManager * accountManager ( ) ;
[ [ nodiscard ] ] Headline * headline ( ) const ;
2024-03-22 20:12:06 -04:00
[ [ nodiscard ] ] QString cachedLogoImage ( ) const ;
2024-07-30 18:43:06 -04:00
# ifdef BUILD_SYNC
2024-07-28 11:17:30 -04:00
[ [ nodiscard ] ] SyncManager * syncManager ( ) const ;
2024-07-30 18:43:06 -04:00
# endif
2023-10-11 14:49:24 -04:00
2023-10-11 17:45:02 -04:00
Q_SIGNALS :
2023-07-30 08:49:34 -04:00
void loadingFinished ( ) ;
void successfulLaunch ( ) ;
2024-07-30 19:47:26 -04:00
void gameClosed ( Profile * profile ) ;
2023-07-30 08:49:34 -04:00
void loginError ( QString message ) ;
2023-10-08 19:07:34 -04:00
void dalamudError ( QString message ) ;
2024-04-01 14:54:41 -04:00
void miscError ( QString message ) ;
2023-10-11 17:45:02 -04:00
void stageChanged ( QString message , QString explanation = { } ) ;
2023-07-30 14:56:24 -04:00
void stageIndeterminate ( ) ;
void stageDeterminate ( int min , int max , int value ) ;
2023-07-30 08:49:34 -04:00
void newsChanged ( ) ;
2023-09-16 20:12:01 -04:00
void currentProfileChanged ( ) ;
2023-09-17 19:20:41 -04:00
void autoLoginProfileChanged ( ) ;
2024-03-22 20:12:06 -04:00
void cachedLogoImageChanged ( ) ;
2024-07-30 19:58:40 -04:00
void showWindow ( ) ;
2023-07-30 08:49:34 -04:00
2023-10-11 17:45:02 -04:00
protected :
friend class Patcher ;
bool m_isPatching = false ;
2023-07-30 08:49:34 -04:00
private :
2023-09-17 18:43:58 -04:00
QCoro : : Task < > beginLogin ( LoginInformation & info ) ;
2023-09-16 18:37:42 -04:00
QCoro : : Task < > fetchNews ( ) ;
2024-07-30 20:41:35 -04:00
QCoro : : Task < > handleGameExit ( const Profile * profile ) ;
2024-07-30 19:47:26 -04:00
2024-08-22 18:50:43 -04:00
/// Updates FFXIV.cfg with some recommended options like turning the opening cutscene movie off
void updateConfig ( const Account * account ) ;
2023-09-17 08:31:24 -04:00
SteamAPI * m_steamApi = nullptr ;
2023-07-30 08:49:34 -04:00
bool m_loadingFinished = false ;
ProfileManager * m_profileManager = nullptr ;
AccountManager * m_accountManager = nullptr ;
2023-10-11 14:13:42 -04:00
SapphireLogin * m_sapphireLogin = nullptr ;
SquareEnixLogin * m_squareEnixLogin = nullptr ;
2023-09-17 08:31:24 -04:00
2023-10-11 13:34:43 -04:00
QNetworkAccessManager * m_mgr = nullptr ;
2023-07-30 08:49:34 -04:00
Headline * m_headline = nullptr ;
2023-10-11 13:25:24 -04:00
LauncherSettings * m_settings = nullptr ;
2023-10-11 14:30:21 -04:00
GameRunner * m_runner = nullptr ;
2024-03-22 20:12:06 -04:00
QString m_cachedLogoImage ;
2024-07-30 18:43:06 -04:00
# ifdef BUILD_SYNC
2024-07-28 11:17:30 -04:00
SyncManager * m_syncManager = nullptr ;
2024-07-30 18:43:06 -04:00
# endif
2023-09-16 20:12:01 -04:00
int m_currentProfileIndex = 0 ;
2023-07-30 08:49:34 -04:00
} ;