2021-11-23 15:34:23 -05:00
# include "launchercore.h"
# include "launcherwindow.h"
2021-11-01 09:54:58 -04:00
# include <QApplication>
2021-11-23 15:34:23 -05:00
# include <QCommandLineParser>
2022-03-01 17:21:29 -05:00
# include <keychain.h>
2022-03-16 18:39:13 -04:00
# include <QDir>
2021-11-23 16:02:02 -05:00
# include "sapphirelauncher.h"
# include "squareboot.h"
2022-03-16 18:39:13 -04:00
# include "gameinstaller.h"
2021-11-01 09:54:58 -04:00
int main ( int argc , char * argv [ ] ) {
2022-04-09 17:02:25 -04:00
QCoreApplication : : setAttribute ( Qt : : AA_EnableHighDpiScaling ) ;
QCoreApplication : : setAttribute ( Qt : : AA_UseHighDpiPixmaps ) ;
2021-11-01 09:54:58 -04:00
QApplication app ( argc , argv ) ;
2021-11-01 14:52:34 -04:00
# ifdef NDEBUG
2022-02-23 19:00:17 -05:00
QCoreApplication : : setApplicationName ( " astra " ) ;
2021-11-01 14:52:34 -04:00
# else
2022-02-23 19:00:17 -05:00
QCoreApplication : : setApplicationName ( " astra-debug " ) ;
2021-11-01 14:52:34 -04:00
# endif
2021-11-23 15:34:23 -05:00
LauncherCore c ;
QCommandLineParser parser ;
parser . setApplicationDescription ( " Cross-platform FFXIV Launcher " ) ;
parser . addHelpOption ( ) ;
parser . addVersionOption ( ) ;
2021-11-23 15:37:02 -05:00
QCommandLineOption noguiOption ( " nogui " , " Don't open a main window. " ) ;
parser . addOption ( noguiOption ) ;
2021-11-23 16:02:02 -05:00
QCommandLineOption autologinOption ( " autologin " , " Auto-login with the default profile. This requires the profile to have remember username/password enabled! " ) ;
parser . addOption ( autologinOption ) ;
QCommandLineOption profileOption ( " default-profile " , " Profile to use for default profile and autologin. " , " profile " ) ;
parser . addOption ( profileOption ) ;
2021-11-23 15:34:23 -05:00
parser . process ( app ) ;
2021-11-23 16:02:02 -05:00
if ( parser . isSet ( profileOption ) ) {
c . defaultProfileIndex = c . getProfileIndex ( parser . value ( profileOption ) ) ;
if ( c . defaultProfileIndex = = - 1 ) {
qInfo ( ) < < " The profile \" " < < parser . value ( profileOption ) < < " \" does not exist! " ;
return 0 ;
}
}
if ( parser . isSet ( autologinOption ) ) {
2022-03-17 11:41:02 -04:00
auto profile = c . getProfile ( c . defaultProfileIndex ) ;
2021-11-23 16:02:02 -05:00
if ( ! profile . rememberUsername | | ! profile . rememberPassword ) {
qInfo ( ) < < " Profile does not have a username and/or password saved, autologin disabled. " ;
return 0 ;
}
auto loop = new QEventLoop ( ) ;
QString username , password ;
auto usernameJob = new QKeychain : : ReadPasswordJob ( " LauncherWindow " ) ;
usernameJob - > setKey ( profile . name + " -username " ) ;
usernameJob - > start ( ) ;
c . connect ( usernameJob , & QKeychain : : ReadPasswordJob : : finished , [ loop , usernameJob , & username ] ( QKeychain : : Job * j ) {
username = usernameJob - > textData ( ) ;
loop - > quit ( ) ;
} ) ;
loop - > exec ( ) ;
auto passwordJob = new QKeychain : : ReadPasswordJob ( " LauncherWindow " ) ;
passwordJob - > setKey ( profile . name + " -password " ) ;
passwordJob - > start ( ) ;
c . connect ( passwordJob , & QKeychain : : ReadPasswordJob : : finished , [ loop , passwordJob , & password ] ( QKeychain : : Job * j ) {
password = passwordJob - > textData ( ) ;
loop - > quit ( ) ;
} ) ;
loop - > exec ( ) ;
auto info = LoginInformation { & profile , username , password , " " } ;
if ( profile . isSapphire ) {
c . sapphireLauncher - > login ( profile . lobbyURL , info ) ;
} else {
c . squareBoot - > bootCheck ( info ) ;
}
}
2022-04-09 16:59:04 -04:00
LauncherWindow w ( c ) ;
if ( ! parser . isSet ( noguiOption ) ) {
w . show ( ) ;
2022-03-16 18:39:13 -04:00
2022-04-09 16:59:04 -04:00
if ( ! QDir ( c . getProfile ( c . defaultProfileIndex ) . gamePath ) . exists ( ) ) {
2022-04-09 17:38:32 -04:00
auto messageBox = new QMessageBox ( QMessageBox : : Information , " No Game Found " , " FFXIV is not installed. Would you like to install it now? " , QMessageBox : : NoButton , & w ) ;
2022-03-17 11:41:02 -04:00
2022-04-09 16:59:04 -04:00
auto installButton = messageBox - > addButton ( " Install Game " , QMessageBox : : HelpRole ) ;
c . connect ( installButton , & QPushButton : : clicked , [ & c , messageBox ] {
installGame ( c , [ messageBox , & c ] {
c . readGameVersion ( ) ;
messageBox - > close ( ) ;
} ) ;
2022-03-16 18:39:13 -04:00
} ) ;
2022-04-09 16:59:04 -04:00
messageBox - > addButton ( QMessageBox : : StandardButton : : No ) ;
2022-03-16 18:39:13 -04:00
2022-04-09 16:59:04 -04:00
messageBox - > show ( ) ;
}
2021-11-23 15:37:02 -05:00
}
2021-11-01 09:54:58 -04:00
return app . exec ( ) ;
}