2021-11-23 15:34:23 -05:00
|
|
|
#include "launcherwindow.h"
|
|
|
|
|
|
|
|
#include <QMenuBar>
|
2022-03-01 17:21:29 -05:00
|
|
|
#include <keychain.h>
|
2021-11-23 15:34:23 -05:00
|
|
|
#include <QFormLayout>
|
2021-12-03 17:19:58 -05:00
|
|
|
#include <QApplication>
|
2022-02-24 09:28:11 -05:00
|
|
|
#include <QDesktopServices>
|
2022-03-10 10:03:17 -05:00
|
|
|
#include <QNetworkReply>
|
|
|
|
#include <QTreeWidgetItem>
|
|
|
|
#include <QHeaderView>
|
2022-04-14 19:20:21 -04:00
|
|
|
#include <QDirIterator>
|
2022-04-17 21:17:58 -04:00
|
|
|
#include <QTimer>
|
|
|
|
#include <QScrollBar>
|
2021-11-23 15:34:23 -05:00
|
|
|
|
|
|
|
#include "settingswindow.h"
|
|
|
|
#include "squareboot.h"
|
|
|
|
#include "squarelauncher.h"
|
|
|
|
#include "sapphirelauncher.h"
|
|
|
|
#include "assetupdater.h"
|
2022-03-10 10:03:17 -05:00
|
|
|
#include "headline.h"
|
2022-03-14 13:19:50 -04:00
|
|
|
#include "config.h"
|
2022-04-10 19:56:14 -04:00
|
|
|
#include "aboutwindow.h"
|
2022-04-14 16:29:23 -04:00
|
|
|
#include "gameinstaller.h"
|
2022-04-17 21:17:58 -04:00
|
|
|
#include "bannerwidget.h"
|
2022-04-14 19:20:21 -04:00
|
|
|
#include "encryptedarg.h"
|
2021-11-23 15:34:23 -05:00
|
|
|
|
|
|
|
LauncherWindow::LauncherWindow(LauncherCore& core, QWidget* parent) : QMainWindow(parent), core(core) {
|
2022-02-23 19:00:17 -05:00
|
|
|
setWindowTitle("Astra");
|
|
|
|
|
2021-11-23 15:34:23 -05:00
|
|
|
connect(&core, &LauncherCore::settingsChanged, this, &LauncherWindow::reloadControls);
|
|
|
|
|
|
|
|
QMenu* toolsMenu = menuBar()->addMenu("Tools");
|
|
|
|
|
2022-04-14 19:20:21 -04:00
|
|
|
launchOfficial = toolsMenu->addAction("Open Official Launcher...");
|
2022-02-24 09:28:11 -05:00
|
|
|
launchOfficial->setIcon(QIcon::fromTheme("application-x-executable"));
|
2021-11-23 15:34:23 -05:00
|
|
|
connect(launchOfficial, &QAction::triggered, [=] {
|
2022-04-14 19:20:21 -04:00
|
|
|
struct Argument {
|
|
|
|
QString key, value;
|
|
|
|
};
|
|
|
|
|
|
|
|
QString executeArg("%1%2%3%4");
|
|
|
|
QDateTime dateTime = QDateTime::currentDateTime();
|
|
|
|
executeArg = executeArg.arg(dateTime.date().month() + 1, 2, 10, QLatin1Char('0'));
|
|
|
|
executeArg = executeArg.arg(dateTime.date().day(), 2, 10, QLatin1Char('0'));
|
|
|
|
executeArg = executeArg.arg(dateTime.time().hour(), 2, 10, QLatin1Char('0'));
|
|
|
|
executeArg = executeArg.arg(dateTime.time().minute(), 2, 10, QLatin1Char('0'));
|
|
|
|
|
|
|
|
QList<Argument> arguments;
|
|
|
|
arguments.push_back({"ExecuteArg", executeArg});
|
|
|
|
|
|
|
|
// find user path
|
|
|
|
QString userPath;
|
|
|
|
|
|
|
|
// TODO: don't put this here
|
|
|
|
QString searchDir;
|
|
|
|
#if defined(Q_OS_LINUX) || defined(Q_OS_MAC)
|
|
|
|
searchDir = currentProfile().winePrefixPath + "/drive_c/Users";
|
|
|
|
#else
|
|
|
|
searchDir = "C:/Users";
|
|
|
|
#endif
|
|
|
|
|
|
|
|
QDirIterator it(searchDir);
|
|
|
|
while (it.hasNext()) {
|
|
|
|
QString dir = it.next();
|
|
|
|
QFileInfo fi(dir);
|
|
|
|
QString fileName = fi.fileName();
|
|
|
|
|
|
|
|
// FIXME: is there no easier way to filter out these in Qt?
|
|
|
|
if(fi.fileName() != "Public" && fi.fileName() != "." && fi.fileName() != "..") {
|
|
|
|
userPath = fileName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-27 11:44:06 -04:00
|
|
|
arguments.push_back({"UserPath", QString(R"(C:\Users\%1\My Documents\My Games\FINAL FANTASY XIV - A Realm Reborn)").arg(userPath)});
|
2022-04-14 19:20:21 -04:00
|
|
|
|
|
|
|
const QString argFormat = " /%1 =%2";
|
|
|
|
|
|
|
|
QString argJoined;
|
2022-04-27 11:44:06 -04:00
|
|
|
for(auto& arg : arguments) {
|
|
|
|
argJoined += argFormat.arg(arg.key, arg.value.replace(" ", " "));
|
2022-04-14 19:20:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
QString finalArg = encryptGameArg(argJoined);
|
|
|
|
|
|
|
|
this->core.launchExecutable(currentProfile(), {currentProfile().gamePath + "/boot/ffxivlauncher64.exe", finalArg});
|
2021-11-23 15:34:23 -05:00
|
|
|
});
|
|
|
|
|
2022-04-09 16:56:17 -04:00
|
|
|
launchSysInfo = toolsMenu->addAction("Open System Info...");
|
2022-02-24 09:28:11 -05:00
|
|
|
launchSysInfo->setIcon(QIcon::fromTheme("application-x-executable"));
|
2021-11-23 15:34:23 -05:00
|
|
|
connect(launchSysInfo, &QAction::triggered, [=] {
|
|
|
|
this->core.launchExecutable(currentProfile(), {currentProfile().gamePath + "/boot/ffxivsysinfo64.exe"});
|
|
|
|
});
|
|
|
|
|
2022-04-09 16:56:17 -04:00
|
|
|
launchCfgBackup = toolsMenu->addAction("Open Config Backup...");
|
2022-02-24 09:28:11 -05:00
|
|
|
launchCfgBackup->setIcon(QIcon::fromTheme("application-x-executable"));
|
2021-11-23 15:34:23 -05:00
|
|
|
connect(launchCfgBackup, &QAction::triggered, [=] {
|
|
|
|
this->core.launchExecutable(currentProfile(), {currentProfile().gamePath + "/boot/ffxivconfig64.exe"});
|
|
|
|
});
|
|
|
|
|
2022-02-24 09:28:11 -05:00
|
|
|
toolsMenu->addSeparator();
|
2021-11-23 15:34:23 -05:00
|
|
|
|
2022-04-09 16:56:17 -04:00
|
|
|
openGameDir = toolsMenu->addAction("Open Game Directory...");
|
2022-02-24 09:28:11 -05:00
|
|
|
openGameDir->setIcon(QIcon::fromTheme("document-open"));
|
|
|
|
connect(openGameDir, &QAction::triggered, [=] {
|
|
|
|
openPath(currentProfile().gamePath);
|
2021-11-23 15:34:23 -05:00
|
|
|
});
|
|
|
|
|
2022-04-14 16:29:23 -04:00
|
|
|
QMenu* gameMenu = menuBar()->addMenu("Game");
|
|
|
|
|
|
|
|
auto installGameAction = gameMenu->addAction("Install game...");
|
|
|
|
connect(installGameAction, &QAction::triggered, [this] {
|
|
|
|
// TODO: lol duplication
|
|
|
|
auto messageBox = new QMessageBox(this);
|
|
|
|
messageBox->setIcon(QMessageBox::Icon::Question);
|
|
|
|
messageBox->setText("Warning");
|
|
|
|
messageBox->setInformativeText("FFXIV will be installed to your selected game directory.");
|
|
|
|
|
|
|
|
QString detailedText = QString("Astra will install FFXIV for you at '%1'").arg(this->currentProfile().gamePath);
|
|
|
|
detailedText.append("\n\nIf you do not wish to install it to this location, please change your profile settings.");
|
|
|
|
|
|
|
|
messageBox->setDetailedText(detailedText);
|
|
|
|
messageBox->setWindowModality(Qt::WindowModal);
|
|
|
|
|
|
|
|
auto installButton = messageBox->addButton("Install Game", QMessageBox::YesRole);
|
|
|
|
connect(installButton, &QPushButton::clicked, [this, messageBox] {
|
|
|
|
installGame(this->core, this->currentProfile(), [this, messageBox] {
|
|
|
|
this->core.readGameVersion();
|
|
|
|
|
|
|
|
messageBox->close();
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
messageBox->addButton(QMessageBox::StandardButton::No);
|
|
|
|
messageBox->setDefaultButton(installButton);
|
|
|
|
|
|
|
|
messageBox->exec();
|
|
|
|
});
|
|
|
|
|
2022-02-24 09:28:11 -05:00
|
|
|
QMenu* fileMenu = menuBar()->addMenu("Settings");
|
|
|
|
|
|
|
|
QAction* settingsAction = fileMenu->addAction("Configure Astra...");
|
2022-04-09 17:57:03 -04:00
|
|
|
settingsAction->setIcon(QIcon::fromTheme("configure"));
|
2022-04-10 21:00:05 -04:00
|
|
|
settingsAction->setMenuRole(QAction::MenuRole::PreferencesRole);
|
2022-02-24 09:28:11 -05:00
|
|
|
connect(settingsAction, &QAction::triggered, [=] {
|
2022-03-09 08:08:03 -05:00
|
|
|
auto window = new SettingsWindow(0, *this, this->core, this);
|
|
|
|
connect(&this->core, &LauncherCore::settingsChanged, window, &SettingsWindow::reloadControls);
|
|
|
|
window->show();
|
|
|
|
});
|
|
|
|
|
|
|
|
QAction* profilesAction = fileMenu->addAction("Configure Profiles...");
|
2022-04-09 17:57:03 -04:00
|
|
|
profilesAction->setIcon(QIcon::fromTheme("configure"));
|
2022-04-10 18:23:34 -04:00
|
|
|
profilesAction->setMenuRole(QAction::MenuRole::NoRole);
|
2022-03-09 08:08:03 -05:00
|
|
|
connect(profilesAction, &QAction::triggered, [=] {
|
|
|
|
auto window = new SettingsWindow(1, *this, this->core, this);
|
2022-02-24 09:28:11 -05:00
|
|
|
connect(&this->core, &LauncherCore::settingsChanged, window, &SettingsWindow::reloadControls);
|
|
|
|
window->show();
|
|
|
|
});
|
|
|
|
|
|
|
|
#if defined(Q_OS_MAC) || defined(Q_OS_LINUX)
|
2022-03-09 08:08:03 -05:00
|
|
|
fileMenu->addSeparator();
|
|
|
|
|
2022-04-09 17:28:24 -04:00
|
|
|
wineCfg = fileMenu->addAction("Configure Wine...");
|
2022-04-10 21:00:05 -04:00
|
|
|
wineCfg->setMenuRole(QAction::MenuRole::NoRole);
|
2022-04-09 17:57:03 -04:00
|
|
|
wineCfg->setIcon(QIcon::fromTheme("configure"));
|
2022-02-24 09:28:11 -05:00
|
|
|
connect(wineCfg, &QAction::triggered, [=] {
|
2022-04-14 17:48:06 -04:00
|
|
|
this->core.launchExternalTool(currentProfile(), {"regedit.exe"});
|
2021-11-23 15:34:23 -05:00
|
|
|
});
|
|
|
|
#endif
|
|
|
|
|
2021-12-03 17:19:58 -05:00
|
|
|
QMenu* helpMenu = menuBar()->addMenu("Help");
|
2022-02-23 19:00:17 -05:00
|
|
|
QAction* showAbout = helpMenu->addAction("About Astra");
|
2022-02-24 09:28:11 -05:00
|
|
|
showAbout->setIcon(QIcon::fromTheme("help-about"));
|
2021-12-03 17:19:58 -05:00
|
|
|
connect(showAbout, &QAction::triggered, [=] {
|
2022-04-10 19:56:14 -04:00
|
|
|
auto window = new AboutWindow(this);
|
|
|
|
window->show();
|
2021-12-03 17:19:58 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
QAction* showAboutQt = helpMenu->addAction("About Qt");
|
2022-02-24 09:28:11 -05:00
|
|
|
showAboutQt->setIcon(QIcon::fromTheme("help-about"));
|
2021-12-03 17:19:58 -05:00
|
|
|
connect(showAboutQt, &QAction::triggered, [=] {
|
2022-04-09 17:05:12 -04:00
|
|
|
QMessageBox::aboutQt(this);
|
2021-12-03 17:19:58 -05:00
|
|
|
});
|
|
|
|
|
2022-04-10 16:58:29 -04:00
|
|
|
layout = new QGridLayout();
|
2022-03-10 10:03:17 -05:00
|
|
|
|
2022-04-17 21:17:58 -04:00
|
|
|
bannerScrollArea = new QScrollArea();
|
|
|
|
bannerLayout = new QHBoxLayout();
|
|
|
|
bannerLayout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
bannerLayout->setSpacing(0);
|
|
|
|
bannerLayout->setSizeConstraint(QLayout::SizeConstraint::SetMinAndMaxSize);
|
|
|
|
bannerParentWidget = new QWidget();
|
|
|
|
bannerParentWidget->setFixedHeight(250);
|
|
|
|
bannerScrollArea->setFixedWidth(640);
|
|
|
|
bannerScrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
|
|
bannerScrollArea->verticalScrollBar()->setEnabled(false);
|
|
|
|
bannerScrollArea->horizontalScrollBar()->setEnabled(false);
|
|
|
|
|
|
|
|
bannerScrollArea->setWidget(bannerParentWidget);
|
|
|
|
bannerParentWidget->setLayout(bannerLayout);
|
2022-03-10 10:03:17 -05:00
|
|
|
|
|
|
|
newsListView = new QTreeWidget();
|
|
|
|
newsListView->setColumnCount(2);
|
|
|
|
newsListView->setHeaderLabels({"Title", "Date"});
|
|
|
|
connect(newsListView, &QTreeWidget::itemClicked, [](QTreeWidgetItem* item, int column) {
|
|
|
|
auto url = item->data(0, Qt::UserRole).toUrl();
|
|
|
|
qInfo() << "clicked" << url;
|
|
|
|
QDesktopServices::openUrl(url);
|
|
|
|
});
|
|
|
|
|
2022-04-10 17:43:05 -04:00
|
|
|
loginLayout = new QFormLayout();
|
2022-03-10 10:03:17 -05:00
|
|
|
layout->addLayout(loginLayout, 0, 1, 1, 1);
|
2021-11-23 15:34:23 -05:00
|
|
|
|
|
|
|
profileSelect = new QComboBox();
|
|
|
|
connect(profileSelect, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged), [=](int index) {
|
|
|
|
reloadControls();
|
|
|
|
});
|
|
|
|
|
2022-03-10 10:03:17 -05:00
|
|
|
loginLayout->addRow("Profile", profileSelect);
|
2021-11-23 15:34:23 -05:00
|
|
|
|
|
|
|
usernameEdit = new QLineEdit();
|
2022-03-10 10:03:17 -05:00
|
|
|
loginLayout->addRow("Username", usernameEdit);
|
2021-11-23 15:34:23 -05:00
|
|
|
|
|
|
|
rememberUsernameBox = new QCheckBox();
|
|
|
|
connect(rememberUsernameBox, &QCheckBox::stateChanged, [=](int) {
|
|
|
|
currentProfile().rememberUsername = rememberUsernameBox->isChecked();
|
|
|
|
this->core.saveSettings();
|
|
|
|
});
|
2022-03-10 10:03:17 -05:00
|
|
|
loginLayout->addRow("Remember Username?", rememberUsernameBox);
|
2021-11-23 15:34:23 -05:00
|
|
|
|
|
|
|
passwordEdit = new QLineEdit();
|
|
|
|
passwordEdit->setEchoMode(QLineEdit::EchoMode::Password);
|
2022-03-10 10:03:17 -05:00
|
|
|
loginLayout->addRow("Password", passwordEdit);
|
2021-11-23 15:34:23 -05:00
|
|
|
|
|
|
|
rememberPasswordBox = new QCheckBox();
|
|
|
|
connect(rememberPasswordBox, &QCheckBox::stateChanged, [=](int) {
|
|
|
|
currentProfile().rememberPassword = rememberPasswordBox->isChecked();
|
|
|
|
this->core.saveSettings();
|
|
|
|
});
|
2022-03-10 10:03:17 -05:00
|
|
|
loginLayout->addRow("Remember Password?", rememberPasswordBox);
|
2021-11-23 15:34:23 -05:00
|
|
|
|
|
|
|
otpEdit = new QLineEdit();
|
2021-12-02 14:17:33 -05:00
|
|
|
loginButton = new QPushButton("Login");
|
2021-11-23 15:34:23 -05:00
|
|
|
registerButton = new QPushButton("Register");
|
|
|
|
|
2022-04-27 11:50:29 -04:00
|
|
|
connect(otpEdit, &QLineEdit::returnPressed, [this] {
|
|
|
|
this->core.assetUpdater->update(currentProfile());
|
|
|
|
});
|
|
|
|
|
|
|
|
connect(passwordEdit, &QLineEdit::returnPressed, [this] {
|
|
|
|
this->core.assetUpdater->update(currentProfile());
|
|
|
|
});
|
|
|
|
|
2021-11-23 15:34:23 -05:00
|
|
|
auto emptyWidget = new QWidget();
|
|
|
|
emptyWidget->setLayout(layout);
|
|
|
|
setCentralWidget(emptyWidget);
|
|
|
|
|
|
|
|
connect(core.assetUpdater, &AssetUpdater::finishedUpdating, [=] {
|
|
|
|
auto info = LoginInformation{¤tProfile(), usernameEdit->text(), passwordEdit->text(), otpEdit->text()};
|
|
|
|
|
2022-02-24 09:38:41 -05:00
|
|
|
#ifndef QT_DEBUG
|
2021-11-23 15:34:23 -05:00
|
|
|
if(currentProfile().rememberUsername) {
|
|
|
|
auto job = new QKeychain::WritePasswordJob("LauncherWindow");
|
|
|
|
job->setTextData(usernameEdit->text());
|
|
|
|
job->setKey(currentProfile().name + "-username");
|
|
|
|
job->start();
|
|
|
|
}
|
2022-02-24 09:38:41 -05:00
|
|
|
#endif
|
2021-11-23 15:34:23 -05:00
|
|
|
|
2022-02-24 09:38:41 -05:00
|
|
|
#ifndef QT_DEBUG
|
2021-11-23 15:34:23 -05:00
|
|
|
if(currentProfile().rememberPassword) {
|
|
|
|
auto job = new QKeychain::WritePasswordJob("LauncherWindow");
|
|
|
|
job->setTextData(passwordEdit->text());
|
|
|
|
job->setKey(currentProfile().name + "-password");
|
|
|
|
job->start();
|
|
|
|
}
|
2022-02-24 09:38:41 -05:00
|
|
|
#endif
|
2021-11-23 15:34:23 -05:00
|
|
|
|
|
|
|
if(currentProfile().isSapphire) {
|
2022-03-14 13:19:50 -04:00
|
|
|
//this->core.sapphireLauncher->login(currentProfile().lobbyURL, info);
|
2021-11-23 15:34:23 -05:00
|
|
|
} else {
|
|
|
|
this->core.squareBoot->bootCheck(info);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
connect(loginButton, &QPushButton::released, [=] {
|
|
|
|
// update the assets first if needed, then it calls the slot above :-)
|
|
|
|
this->core.assetUpdater->update(currentProfile());
|
|
|
|
});
|
|
|
|
|
|
|
|
connect(registerButton, &QPushButton::released, [=] {
|
|
|
|
if(currentProfile().isSapphire) {
|
|
|
|
auto info = LoginInformation{¤tProfile(), usernameEdit->text(), passwordEdit->text(), otpEdit->text()};
|
|
|
|
this->core.sapphireLauncher->registerAccount(currentProfile().lobbyURL, info);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-02-24 09:10:00 -05:00
|
|
|
connect(&core, &LauncherCore::successfulLaunch, [&] {
|
2022-04-17 22:53:39 -04:00
|
|
|
if(core.appSettings.closeWhenLaunched)
|
|
|
|
hide();
|
2022-02-24 09:10:00 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
connect(&core, &LauncherCore::gameClosed, [&] {
|
|
|
|
if(core.appSettings.closeWhenLaunched)
|
|
|
|
QCoreApplication::quit();
|
|
|
|
});
|
|
|
|
|
2022-04-17 21:17:58 -04:00
|
|
|
getHeadline(core,[&](Headline headline) {
|
|
|
|
this->headline = headline;
|
|
|
|
reloadNews();
|
|
|
|
});
|
|
|
|
|
2021-11-23 15:34:23 -05:00
|
|
|
reloadControls();
|
|
|
|
}
|
|
|
|
|
|
|
|
ProfileSettings LauncherWindow::currentProfile() const {
|
|
|
|
return core.getProfile(profileSelect->currentIndex());
|
|
|
|
}
|
|
|
|
|
|
|
|
ProfileSettings& LauncherWindow::currentProfile() {
|
|
|
|
return core.getProfile(profileSelect->currentIndex());
|
|
|
|
}
|
|
|
|
|
|
|
|
void LauncherWindow::reloadControls() {
|
|
|
|
if(currentlyReloadingControls)
|
|
|
|
return;
|
|
|
|
|
|
|
|
currentlyReloadingControls = true;
|
|
|
|
|
|
|
|
const int oldIndex = profileSelect->currentIndex();
|
|
|
|
|
|
|
|
profileSelect->clear();
|
|
|
|
|
|
|
|
for(const auto& profile : core.profileList()) {
|
|
|
|
profileSelect->addItem(profile);
|
|
|
|
}
|
|
|
|
|
|
|
|
profileSelect->setCurrentIndex(oldIndex);
|
|
|
|
|
|
|
|
if(profileSelect->currentIndex() == -1) {
|
|
|
|
profileSelect->setCurrentIndex(core.defaultProfileIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
rememberUsernameBox->setChecked(currentProfile().rememberUsername);
|
2022-02-24 09:38:41 -05:00
|
|
|
#ifndef QT_DEBUG
|
2021-11-23 15:34:23 -05:00
|
|
|
if(currentProfile().rememberUsername) {
|
|
|
|
auto job = new QKeychain::ReadPasswordJob("LauncherWindow");
|
|
|
|
job->setKey(currentProfile().name + "-username");
|
|
|
|
job->start();
|
|
|
|
|
|
|
|
connect(job, &QKeychain::ReadPasswordJob::finished, [=](QKeychain::Job* j) {
|
|
|
|
usernameEdit->setText(job->textData());
|
|
|
|
});
|
|
|
|
}
|
2022-02-24 09:38:41 -05:00
|
|
|
#endif
|
2021-11-23 15:34:23 -05:00
|
|
|
|
|
|
|
rememberPasswordBox->setChecked(currentProfile().rememberPassword);
|
2022-02-24 09:38:41 -05:00
|
|
|
#ifndef QT_DEBUG
|
2021-11-23 15:34:23 -05:00
|
|
|
if(currentProfile().rememberPassword) {
|
|
|
|
auto job = new QKeychain::ReadPasswordJob("LauncherWindow");
|
|
|
|
job->setKey(currentProfile().name + "-password");
|
|
|
|
job->start();
|
|
|
|
|
|
|
|
connect(job, &QKeychain::ReadPasswordJob::finished, [=](QKeychain::Job* j) {
|
|
|
|
passwordEdit->setText(job->textData());
|
|
|
|
});
|
|
|
|
}
|
2022-02-24 09:38:41 -05:00
|
|
|
#endif
|
2021-11-23 15:34:23 -05:00
|
|
|
|
2022-04-14 16:42:53 -04:00
|
|
|
bool canLogin = true;
|
|
|
|
if(currentProfile().isSapphire) {
|
|
|
|
if(currentProfile().lobbyURL.isEmpty()) {
|
|
|
|
loginButton->setText("Login (Lobby URL is invalid)");
|
|
|
|
canLogin = false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if(!core.squareLauncher->isGateOpen) {
|
|
|
|
loginButton->setText("Login (Maintenance is in progress)");
|
|
|
|
canLogin = false;
|
|
|
|
}
|
|
|
|
}
|
2021-12-02 14:17:33 -05:00
|
|
|
|
2022-04-09 17:30:19 -04:00
|
|
|
#if defined(Q_OS_LINUX) || defined(Q_OS_MAC)
|
2022-04-14 16:42:53 -04:00
|
|
|
if(!currentProfile().isWineInstalled()) {
|
2022-04-09 17:30:19 -04:00
|
|
|
loginButton->setText("Login (Wine is not installed)");
|
2022-04-14 16:42:53 -04:00
|
|
|
canLogin = false;
|
|
|
|
}
|
2022-04-09 17:30:19 -04:00
|
|
|
#endif
|
2022-04-14 16:42:53 -04:00
|
|
|
if(!currentProfile().isGameInstalled()) {
|
2022-04-09 16:56:17 -04:00
|
|
|
loginButton->setText("Login (Game is not installed)");
|
2022-04-14 16:42:53 -04:00
|
|
|
canLogin = false;
|
2021-12-02 14:17:33 -05:00
|
|
|
}
|
|
|
|
|
2022-04-14 16:42:53 -04:00
|
|
|
if(canLogin)
|
|
|
|
loginButton->setText("Login");
|
|
|
|
|
2022-04-09 16:56:17 -04:00
|
|
|
launchOfficial->setEnabled(currentProfile().isGameInstalled());
|
|
|
|
launchSysInfo->setEnabled(currentProfile().isGameInstalled());
|
|
|
|
launchCfgBackup->setEnabled(currentProfile().isGameInstalled());
|
|
|
|
openGameDir->setEnabled(currentProfile().isGameInstalled());
|
|
|
|
|
2022-04-09 17:28:24 -04:00
|
|
|
#if defined(Q_OS_MAC) || defined(Q_OS_LINUX)
|
|
|
|
wineCfg->setEnabled(currentProfile().isWineInstalled());
|
|
|
|
#endif
|
|
|
|
|
2022-04-17 21:17:58 -04:00
|
|
|
layout->removeWidget(bannerScrollArea);
|
|
|
|
bannerScrollArea->hide();
|
2022-04-10 16:58:29 -04:00
|
|
|
layout->removeWidget(newsListView);
|
|
|
|
newsListView->hide();
|
|
|
|
|
2022-04-10 17:43:05 -04:00
|
|
|
auto field = loginLayout->labelForField(otpEdit);
|
|
|
|
if(field != nullptr)
|
|
|
|
field->deleteLater();
|
|
|
|
|
|
|
|
loginLayout->takeRow(otpEdit);
|
|
|
|
otpEdit->hide();
|
|
|
|
|
|
|
|
if(currentProfile().useOneTimePassword && !currentProfile().isSapphire) {
|
|
|
|
loginLayout->addRow("One-Time Password", otpEdit);
|
|
|
|
otpEdit->show();
|
|
|
|
}
|
|
|
|
|
|
|
|
loginLayout->takeRow(loginButton);
|
|
|
|
loginButton->setEnabled(canLogin);
|
2022-04-14 16:42:53 -04:00
|
|
|
registerButton->setEnabled(canLogin);
|
2022-04-10 17:43:05 -04:00
|
|
|
loginLayout->addRow(loginButton);
|
|
|
|
|
|
|
|
loginLayout->takeRow(registerButton);
|
|
|
|
registerButton->hide();
|
|
|
|
|
|
|
|
if(currentProfile().isSapphire) {
|
|
|
|
loginLayout->addRow(registerButton);
|
|
|
|
registerButton->show();
|
|
|
|
}
|
|
|
|
|
2022-04-17 21:17:58 -04:00
|
|
|
reloadNews();
|
|
|
|
|
|
|
|
currentlyReloadingControls = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LauncherWindow::reloadNews() {
|
2022-04-10 16:58:29 -04:00
|
|
|
if(core.appSettings.showBanners || core.appSettings.showNewsList) {
|
2022-04-17 21:17:58 -04:00
|
|
|
for(auto widget : bannerWidgets) {
|
|
|
|
bannerLayout->removeWidget(widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
bannerWidgets.clear();
|
|
|
|
|
2022-04-10 16:58:29 -04:00
|
|
|
int totalRow = 0;
|
|
|
|
if(core.appSettings.showBanners) {
|
2022-04-17 21:17:58 -04:00
|
|
|
bannerScrollArea->show();
|
|
|
|
layout->addWidget(bannerScrollArea, totalRow++, 0);
|
2022-04-10 16:58:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if(core.appSettings.showNewsList) {
|
|
|
|
newsListView->show();
|
|
|
|
layout->addWidget(newsListView, totalRow++, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
newsListView->clear();
|
|
|
|
|
2022-04-17 21:17:58 -04:00
|
|
|
if (!headline.banner.empty()) {
|
|
|
|
if(core.appSettings.showBanners) {
|
|
|
|
for(auto banner : headline.banner) {
|
|
|
|
auto request = QNetworkRequest(banner.bannerImage);
|
2022-04-10 16:58:29 -04:00
|
|
|
core.buildRequest(currentProfile(), request);
|
|
|
|
|
|
|
|
auto reply = core.mgr->get(request);
|
|
|
|
connect(reply, &QNetworkReply::finished, [=] {
|
2022-04-17 21:17:58 -04:00
|
|
|
auto bannerImageView = new BannerWidget();
|
|
|
|
bannerImageView->setUrl(banner.link);
|
|
|
|
|
2022-04-10 16:58:29 -04:00
|
|
|
QPixmap pixmap;
|
|
|
|
pixmap.loadFromData(reply->readAll());
|
|
|
|
bannerImageView->setPixmap(pixmap);
|
2022-04-17 21:17:58 -04:00
|
|
|
|
|
|
|
bannerLayout->addWidget(bannerImageView);
|
|
|
|
bannerWidgets.push_back(bannerImageView);
|
2022-04-10 16:58:29 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-04-17 21:17:58 -04:00
|
|
|
if(bannerTimer == nullptr) {
|
|
|
|
bannerTimer = new QTimer();
|
|
|
|
connect(bannerTimer, &QTimer::timeout, this, [=] {
|
|
|
|
if (currentBanner >= headline.banner.size())
|
|
|
|
currentBanner = 0;
|
|
|
|
|
|
|
|
bannerScrollArea->ensureVisible(
|
|
|
|
640 * (currentBanner + 1), 0, 0, 0);
|
|
|
|
|
|
|
|
currentBanner++;
|
|
|
|
});
|
|
|
|
bannerTimer->start(5000);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if(bannerTimer != nullptr) {
|
|
|
|
bannerTimer->stop();
|
|
|
|
bannerTimer->deleteLater();
|
|
|
|
bannerTimer = nullptr;
|
2022-04-10 16:58:29 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-17 21:17:58 -04:00
|
|
|
if(core.appSettings.showNewsList) {
|
|
|
|
QTreeWidgetItem* newsItem = new QTreeWidgetItem(
|
|
|
|
(QTreeWidgetItem*)nullptr, QStringList("News"));
|
|
|
|
for (auto news : headline.news) {
|
|
|
|
QTreeWidgetItem* item = new QTreeWidgetItem();
|
|
|
|
item->setText(0, news.title);
|
|
|
|
item->setText(1, QLocale().toString(
|
|
|
|
news.date, QLocale::ShortFormat));
|
|
|
|
item->setData(0, Qt::UserRole, news.url);
|
|
|
|
|
|
|
|
newsItem->addChild(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
QTreeWidgetItem* pinnedItem = new QTreeWidgetItem(
|
|
|
|
(QTreeWidgetItem*)nullptr, QStringList("Pinned"));
|
|
|
|
for (auto pinned : headline.pinned) {
|
|
|
|
QTreeWidgetItem* item = new QTreeWidgetItem();
|
|
|
|
item->setText(0, pinned.title);
|
|
|
|
item->setText(1,
|
|
|
|
QLocale().toString(pinned.date,
|
|
|
|
QLocale::ShortFormat));
|
|
|
|
item->setData(0, Qt::UserRole, pinned.url);
|
|
|
|
|
|
|
|
pinnedItem->addChild(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
QTreeWidgetItem* topicsItem = new QTreeWidgetItem(
|
|
|
|
(QTreeWidgetItem*)nullptr, QStringList("Topics"));
|
|
|
|
for (auto news : headline.topics) {
|
|
|
|
QTreeWidgetItem* item = new QTreeWidgetItem();
|
|
|
|
item->setText(0, news.title);
|
|
|
|
item->setText(1, QLocale().toString(
|
|
|
|
news.date, QLocale::ShortFormat));
|
|
|
|
item->setData(0, Qt::UserRole, news.url);
|
|
|
|
|
|
|
|
topicsItem->addChild(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
newsListView->insertTopLevelItems(
|
|
|
|
0, QList<QTreeWidgetItem*>(
|
|
|
|
{newsItem, pinnedItem, topicsItem}));
|
|
|
|
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
newsListView->expandItem(newsListView->topLevelItem(i));
|
|
|
|
newsListView->resizeColumnToContents(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-02-24 09:28:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void LauncherWindow::openPath(const QString path) {
|
|
|
|
#if defined(Q_OS_WIN)
|
|
|
|
// for some reason, windows requires special treatment (what else is new?)
|
|
|
|
const QFileInfo fileInfo(path);
|
|
|
|
|
|
|
|
QProcess::startDetached("explorer.exe", QStringList(QDir::toNativeSeparators(fileInfo.canonicalFilePath())));
|
|
|
|
#else
|
|
|
|
QDesktopServices::openUrl("file://" + path);
|
|
|
|
#endif
|
|
|
|
}
|