mirror of
https://github.com/redstrate/Astra.git
synced 2025-04-21 04:07:46 +00:00
Separate traditional desktop interface from CLI, in preparation for QML
This commit is contained in:
parent
7ec40b5d23
commit
5307304c57
6 changed files with 166 additions and 104 deletions
|
@ -40,7 +40,11 @@ set(SRC
|
||||||
src/aboutwindow.cpp
|
src/aboutwindow.cpp
|
||||||
include/aboutwindow.h
|
include/aboutwindow.h
|
||||||
src/bannerwidget.cpp
|
src/bannerwidget.cpp
|
||||||
include/bannerwidget.h)
|
include/bannerwidget.h
|
||||||
|
include/desktopinterface.h
|
||||||
|
include/cmdinterface.h
|
||||||
|
src/cmdinterface.cpp
|
||||||
|
src/desktopinterface.cpp)
|
||||||
|
|
||||||
include(FetchContent)
|
include(FetchContent)
|
||||||
|
|
||||||
|
|
18
include/cmdinterface.h
Normal file
18
include/cmdinterface.h
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QCommandLineParser>
|
||||||
|
#include "launchercore.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The CLI interface for Astra, driven primarily by the command-line.
|
||||||
|
*/
|
||||||
|
class CMDInterface {
|
||||||
|
public:
|
||||||
|
CMDInterface(QCommandLineParser& parser);
|
||||||
|
|
||||||
|
bool parse(QCommandLineParser& parser, LauncherCore& core);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QCommandLineOption profileOption = {"default-profile", "Profile to use for default profile and autologin.", "profile"};
|
||||||
|
QCommandLineOption autologinOption = {"autologin", "Auto-login with the default profile. This requires the profile to have remember username/password enabled!"};
|
||||||
|
};
|
15
include/desktopinterface.h
Normal file
15
include/desktopinterface.h
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "launcherwindow.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The desktop, mouse and keyboard-driven interface for Astra. Primarily meant
|
||||||
|
* for regular desktop usage.
|
||||||
|
*/
|
||||||
|
class DesktopInterface {
|
||||||
|
public:
|
||||||
|
DesktopInterface(LauncherCore& core);
|
||||||
|
|
||||||
|
private:
|
||||||
|
LauncherWindow* window = nullptr;
|
||||||
|
};
|
65
src/cmdinterface.cpp
Normal file
65
src/cmdinterface.cpp
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
#include <keychain.h>
|
||||||
|
#include "cmdinterface.h"
|
||||||
|
#include "squareboot.h"
|
||||||
|
#include "sapphirelauncher.h"
|
||||||
|
|
||||||
|
CMDInterface::CMDInterface(QCommandLineParser &parser) {
|
||||||
|
parser.addOption(autologinOption);
|
||||||
|
parser.addOption(profileOption);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CMDInterface::parse(QCommandLineParser &parser, LauncherCore &core) {
|
||||||
|
if(parser.isSet(profileOption)) {
|
||||||
|
core.defaultProfileIndex = core.getProfileIndex(parser.value(profileOption));
|
||||||
|
|
||||||
|
if(core.defaultProfileIndex == -1) {
|
||||||
|
qInfo() << "The profile \"" << parser.value(profileOption) << "\" does not exist!";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(parser.isSet(autologinOption)) {
|
||||||
|
auto profile = core.getProfile(core.defaultProfileIndex);
|
||||||
|
|
||||||
|
if(!profile.rememberUsername || !profile.rememberPassword) {
|
||||||
|
qInfo() << "Profile does not have a username and/or password saved, autologin disabled.";
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto loop = new QEventLoop();
|
||||||
|
QString username, password;
|
||||||
|
|
||||||
|
auto usernameJob = new QKeychain::ReadPasswordJob("LauncherWindow");
|
||||||
|
usernameJob->setKey(profile.name + "-username");
|
||||||
|
usernameJob->start();
|
||||||
|
|
||||||
|
core.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();
|
||||||
|
|
||||||
|
core.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) {
|
||||||
|
core.sapphireLauncher->login(profile.lobbyURL, info);
|
||||||
|
} else {
|
||||||
|
core.squareBoot->bootCheck(info);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
51
src/desktopinterface.cpp
Normal file
51
src/desktopinterface.cpp
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
#include "desktopinterface.h"
|
||||||
|
#include "gameinstaller.h"
|
||||||
|
|
||||||
|
DesktopInterface::DesktopInterface(LauncherCore& core) {
|
||||||
|
window = new LauncherWindow(core);
|
||||||
|
window->show();
|
||||||
|
|
||||||
|
auto defaultProfile = core.getProfile(core.defaultProfileIndex);
|
||||||
|
|
||||||
|
if(!defaultProfile.isGameInstalled()) {
|
||||||
|
auto messageBox = new QMessageBox(window);
|
||||||
|
messageBox->setIcon(QMessageBox::Icon::Question);
|
||||||
|
messageBox->setText("No Game Found");
|
||||||
|
messageBox->setInformativeText("FFXIV is not installed. Would you like to install it now?");
|
||||||
|
|
||||||
|
QString detailedText = QString("Astra will install FFXIV for you at '%1'").arg(core.getProfile(core.defaultProfileIndex).gamePath);
|
||||||
|
detailedText.append("\n\nIf you do not wish to install it to this location, please set it in your default profile first.");
|
||||||
|
|
||||||
|
messageBox->setDetailedText(detailedText);
|
||||||
|
messageBox->setWindowModality(Qt::WindowModal);
|
||||||
|
|
||||||
|
auto installButton = messageBox->addButton("Install Game", QMessageBox::YesRole);
|
||||||
|
core.connect(installButton, &QPushButton::clicked, [&core, messageBox] {
|
||||||
|
installGame(core, core.getProfile(core.defaultProfileIndex), [messageBox, &core] {
|
||||||
|
core.readGameVersion();
|
||||||
|
|
||||||
|
messageBox->close();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
messageBox->addButton(QMessageBox::StandardButton::No);
|
||||||
|
messageBox->setDefaultButton(installButton);
|
||||||
|
|
||||||
|
messageBox->exec();
|
||||||
|
}
|
||||||
|
|
||||||
|
#if defined(Q_OS_LINUX) || defined(Q_OS_MAC)
|
||||||
|
if(!defaultProfile.isWineInstalled()) {
|
||||||
|
auto messageBox = new QMessageBox(window);
|
||||||
|
messageBox->setIcon(QMessageBox::Icon::Critical);
|
||||||
|
messageBox->setText("No Wine Found");
|
||||||
|
messageBox->setInformativeText("Wine is not installed but is required to FFXIV on this operating system.");
|
||||||
|
messageBox->setWindowModality(Qt::WindowModal);
|
||||||
|
|
||||||
|
messageBox->addButton(QMessageBox::StandardButton::Ok);
|
||||||
|
messageBox->setDefaultButton(QMessageBox::StandardButton::Ok);
|
||||||
|
|
||||||
|
messageBox->exec();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
115
src/main.cpp
115
src/main.cpp
|
@ -10,6 +10,8 @@
|
||||||
#include "squareboot.h"
|
#include "squareboot.h"
|
||||||
#include "gameinstaller.h"
|
#include "gameinstaller.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
#include "desktopinterface.h"
|
||||||
|
#include "cmdinterface.h"
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
||||||
|
@ -25,6 +27,11 @@ int main(int argc, char* argv[]) {
|
||||||
|
|
||||||
QCoreApplication::setApplicationVersion(version);
|
QCoreApplication::setApplicationVersion(version);
|
||||||
|
|
||||||
|
// we want to decide which interface to use. this is decided by the
|
||||||
|
// -cli, -desktop, or -tablet
|
||||||
|
// the default is -desktop
|
||||||
|
// cli is a special case where it's always "enabled"
|
||||||
|
|
||||||
QCommandLineParser parser;
|
QCommandLineParser parser;
|
||||||
parser.setApplicationDescription("Cross-platform FFXIV Launcher");
|
parser.setApplicationDescription("Cross-platform FFXIV Launcher");
|
||||||
|
|
||||||
|
@ -34,11 +41,7 @@ int main(int argc, char* argv[]) {
|
||||||
QCommandLineOption noguiOption("nogui", "Don't open a main window.");
|
QCommandLineOption noguiOption("nogui", "Don't open a main window.");
|
||||||
parser.addOption(noguiOption);
|
parser.addOption(noguiOption);
|
||||||
|
|
||||||
QCommandLineOption autologinOption("autologin", "Auto-login with the default profile. This requires the profile to have remember username/password enabled!");
|
auto cmd = new CMDInterface(parser);
|
||||||
parser.addOption(autologinOption);
|
|
||||||
|
|
||||||
QCommandLineOption profileOption("default-profile", "Profile to use for default profile and autologin.", "profile");
|
|
||||||
parser.addOption(profileOption);
|
|
||||||
|
|
||||||
parser.process(app);
|
parser.process(app);
|
||||||
|
|
||||||
|
@ -51,106 +54,12 @@ int main(int argc, char* argv[]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
LauncherCore c;
|
LauncherCore c;
|
||||||
|
|
||||||
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)) {
|
|
||||||
auto profile = c.getProfile(c.defaultProfileIndex);
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
LauncherWindow w(c);
|
LauncherWindow w(c);
|
||||||
if(!parser.isSet(noguiOption)) {
|
if(!parser.isSet(noguiOption)) {
|
||||||
w.show();
|
new DesktopInterface(c);
|
||||||
|
} else {
|
||||||
auto defaultProfile = c.getProfile(c.defaultProfileIndex);
|
if(!cmd->parse(parser, c))
|
||||||
|
return -1;
|
||||||
if(!defaultProfile.isGameInstalled()) {
|
|
||||||
auto messageBox = new QMessageBox(&w);
|
|
||||||
messageBox->setIcon(QMessageBox::Icon::Question);
|
|
||||||
messageBox->setText("No Game Found");
|
|
||||||
messageBox->setInformativeText("FFXIV is not installed. Would you like to install it now?");
|
|
||||||
|
|
||||||
QString detailedText = QString("Astra will install FFXIV for you at '%1'").arg(c.getProfile(c.defaultProfileIndex).gamePath);
|
|
||||||
detailedText.append("\n\nIf you do not wish to install it to this location, please set it in your default profile first.");
|
|
||||||
|
|
||||||
messageBox->setDetailedText(detailedText);
|
|
||||||
messageBox->setWindowModality(Qt::WindowModal);
|
|
||||||
|
|
||||||
auto installButton = messageBox->addButton("Install Game", QMessageBox::YesRole);
|
|
||||||
c.connect(installButton, &QPushButton::clicked, [&c, messageBox] {
|
|
||||||
installGame(c, c.getProfile(c.defaultProfileIndex), [messageBox, &c] {
|
|
||||||
c.readGameVersion();
|
|
||||||
|
|
||||||
messageBox->close();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
messageBox->addButton(QMessageBox::StandardButton::No);
|
|
||||||
messageBox->setDefaultButton(installButton);
|
|
||||||
|
|
||||||
messageBox->exec();
|
|
||||||
}
|
|
||||||
|
|
||||||
#if defined(Q_OS_LINUX) || defined(Q_OS_MAC)
|
|
||||||
if(!defaultProfile.isWineInstalled()) {
|
|
||||||
auto messageBox = new QMessageBox(&w);
|
|
||||||
messageBox->setIcon(QMessageBox::Icon::Critical);
|
|
||||||
messageBox->setText("No Wine Found");
|
|
||||||
messageBox->setInformativeText("Wine is not installed but is required to FFXIV on this operating system.");
|
|
||||||
messageBox->setWindowModality(Qt::WindowModal);
|
|
||||||
|
|
||||||
messageBox->addButton(QMessageBox::StandardButton::Ok);
|
|
||||||
messageBox->setDefaultButton(QMessageBox::StandardButton::Ok);
|
|
||||||
|
|
||||||
messageBox->exec();
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return app.exec();
|
return app.exec();
|
||||||
|
|
Loading…
Add table
Reference in a new issue