Skip to content

Commit

Permalink
Misc code cleanup
Browse files Browse the repository at this point in the history
Make more things const, auto and whatnot
  • Loading branch information
redstrate committed Jul 5, 2024
1 parent 1401f9e commit 27e8169
Show file tree
Hide file tree
Showing 30 changed files with 120 additions and 141 deletions.
10 changes: 5 additions & 5 deletions launcher/include/account.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#include <QDir>
#include <QObject>
#include <QtQml/qqmlregistration.h>
#include <QtQml>
#include <qcorotask.h>

#include "accountconfig.h"
Expand Down Expand Up @@ -104,13 +104,13 @@ class Account : public QObject
void fetchAvatar();
QCoro::Task<> fetchPassword();

/*
* Sets a value in the keychain. This function is asynchronous.
/**
* @brief Sets a value in the keychain. This function is asynchronous.
*/
void setKeychainValue(const QString &key, const QString &value);

/*
* Retrieves a value from the keychain. This function is synchronous.
/**
* @brief Retrieves a value from the keychain. This function is synchronous.
*/
QCoro::Task<QString> getKeychainValue(const QString &key);

Expand Down
3 changes: 1 addition & 2 deletions launcher/include/accountmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#pragma once

#include <QAbstractListModel>
#include <QtQml/qqmlregistration.h>

#include "account.h"

Expand Down Expand Up @@ -36,7 +35,7 @@ class AccountManager : public QAbstractListModel

[[nodiscard]] Account *getByUuid(const QString &uuid) const;

Q_INVOKABLE bool canDelete(Account *account) const;
Q_INVOKABLE bool canDelete(const Account *account) const;
Q_INVOKABLE void deleteAccount(Account *account);

Q_INVOKABLE [[nodiscard]] bool hasAnyAccounts() const;
Expand Down
3 changes: 0 additions & 3 deletions launcher/include/assetupdater.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@

#pragma once

#include <QJsonArray>
#include <QObject>
#include <QTemporaryDir>
#include <qcorotask.h>

#include "launchercore.h"
Expand Down
4 changes: 1 addition & 3 deletions launcher/include/compatibilitytoolinstaller.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@

#pragma once

#include <QObject>
#include <QString>
#include <QtQml/qqmlregistration.h>
#include <QtQml>

class LauncherCore;

Expand Down
1 change: 1 addition & 0 deletions launcher/include/existinginstallmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#pragma once

#include <QtQml>

#include <physis.hpp>

class ExistingInstallModel : public QAbstractListModel
Expand Down
4 changes: 1 addition & 3 deletions launcher/include/gameinstaller.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@

#pragma once

#include <QObject>
#include <QString>
#include <QtQml/qqmlregistration.h>
#include <QtQml>

class LauncherCore;
class Profile;
Expand Down
6 changes: 3 additions & 3 deletions launcher/include/gamerunner.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class GameRunner : public QObject
explicit GameRunner(LauncherCore &launcher, QObject *parent = nullptr);

/// Begins the game executable, but calls to Dalamud if needed.
void beginGameExecutable(Profile &settings, const std::optional<LoginAuth> &auth);
void beginGameExecutable(Profile &profile, const std::optional<LoginAuth> &auth);

private:
/// Starts a vanilla game session with no Dalamud injection.
Expand All @@ -26,10 +26,10 @@ class GameRunner : public QObject
void beginDalamudGame(const QString &gameExecutablePath, Profile &profile, const std::optional<LoginAuth> &auth);

/// Returns the game arguments needed to properly launch the game. This encrypts it too if needed, and it's already joined!
QString getGameArgs(const Profile &profile, const std::optional<LoginAuth> &auth);
QString getGameArgs(const Profile &profile, const std::optional<LoginAuth> &auth) const;

/// This wraps it in wine if needed.
void launchExecutable(const Profile &settings, QProcess *process, const QStringList &args, bool isGame, bool needsRegistrySetup);
void launchExecutable(const Profile &profile, QProcess *process, const QStringList &args, bool isGame, bool needsRegistrySetup);

/// Set a Wine registry key
/// \param settings The profile that's being launched
Expand Down
6 changes: 2 additions & 4 deletions launcher/include/launchercore.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@

#pragma once

#include <QFuture>
#include <QNetworkAccessManager>
#include <QProcess>
#include <QtQml>
#include <qcorotask.h>

Expand Down Expand Up @@ -102,11 +100,11 @@ class LauncherCore : public QObject
Q_INVOKABLE void refreshLogoImage();

[[nodiscard]] Profile *currentProfile() const;
void setCurrentProfile(Profile *profile);
void setCurrentProfile(const Profile *profile);

[[nodiscard]] QString autoLoginProfileName() const;
[[nodiscard]] Profile *autoLoginProfile() const;
void setAutoLoginProfile(Profile *value);
void setAutoLoginProfile(const Profile *value);

// Networking misc.
void buildRequest(const Profile &settings, QNetworkRequest &request);
Expand Down
3 changes: 1 addition & 2 deletions launcher/include/launchersettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@

#pragma once

#include <QObject>
#include <QtQml/qqmlregistration.h>
#include <QtQml>

#include "config.h"
#include "profile.h"
Expand Down
6 changes: 4 additions & 2 deletions launcher/include/patcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@

#pragma once

#include "patchlist.h"
#include <QDir>
#include <QMutex>
#include <QNetworkAccessManager>
#include <QString>
#include <physis.hpp>
#include <qcorotask.h>

#include <physis.hpp>

#include "patchlist.h"

class LauncherCore;

// General-purpose patcher routine. It opens a nice dialog box, handles downloading
Expand Down
11 changes: 5 additions & 6 deletions launcher/include/profile.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@

#pragma once

#include <QObject>
#include <QtLogging>
#include <QtQml/qqmlregistration.h>
#include <QtQml>

#include <physis.hpp>

class Account;
Expand Down Expand Up @@ -150,13 +149,13 @@ class Profile : public QObject
void setDalamudApplicable(bool applicable);

/// @return If Dalamud is enabled, and it's also applicable for the current game version.
bool dalamudShouldLaunch() const;
[[nodiscard]] bool dalamudShouldLaunch() const;

[[nodiscard]] QString compatibilityToolVersion() const;
void setCompatibilityToolVersion(const QString &version);

BootData *bootData();
GameData *gameData();
BootData *bootData() const;
GameData *gameData() const;

[[nodiscard]] bool loggedIn() const;
void setLoggedIn(bool value);
Expand Down
5 changes: 2 additions & 3 deletions launcher/include/profilemanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@

#pragma once

#include <QAbstractListModel>
#include <QtQml/qqmlregistration.h>
#include <QtQml>

#include "profile.h"

Expand Down Expand Up @@ -41,7 +40,7 @@ class ProfileManager : public QAbstractListModel
[[nodiscard]] QList<Profile *> profiles() const;
[[nodiscard]] int numProfiles() const;

Q_INVOKABLE bool canDelete(Profile *account) const;
Q_INVOKABLE bool canDelete(const Profile *account) const;

[[nodiscard]] Q_INVOKABLE bool hasAnyExistingInstallations() const;

Expand Down
3 changes: 1 addition & 2 deletions launcher/include/sapphirelogin.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

#pragma once

#include <QString>

#include "launchercore.h"

class SapphireLogin : QObject
Expand All @@ -13,6 +11,7 @@ class SapphireLogin : QObject
explicit SapphireLogin(LauncherCore &window, QObject *parent = nullptr);

/// Begins the login process for Sapphire servers
/// \param lobbyUrl The URL to the Sapphire lobby server
/// \param info The required login information
QCoro::Task<std::optional<LoginAuth>> login(const QString &lobbyUrl, const LoginInformation &info);

Expand Down
35 changes: 18 additions & 17 deletions launcher/src/account.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#include "account.h"

#include <QEventLoop>
#include <QNetworkReply>
#include <QNetworkRequest>
#include <cotp.h>
Expand Down Expand Up @@ -84,7 +83,7 @@ bool Account::isSapphire() const
return m_config.isSapphire();
}

void Account::setIsSapphire(bool value)
void Account::setIsSapphire(const bool value)
{
if (m_config.isSapphire() != value) {
m_config.setIsSapphire(value);
Expand All @@ -98,10 +97,10 @@ QString Account::lobbyUrl() const
return m_config.lobbyUrl();
}

void Account::setLobbyUrl(const QString &value)
void Account::setLobbyUrl(const QString &url)
{
if (m_config.lobbyUrl() != value) {
m_config.setLobbyUrl(value);
if (m_config.lobbyUrl() != url) {
m_config.setLobbyUrl(url);
m_config.save();
Q_EMIT lobbyUrlChanged();
}
Expand Down Expand Up @@ -194,7 +193,7 @@ void Account::setPassword(const QString &password)

QString Account::getOTP()
{
auto otpSecret = QCoro::waitFor(getKeychainValue(QStringLiteral("otp-secret")));
const auto otpSecret = QCoro::waitFor(getKeychainValue(QStringLiteral("otp-secret")));
if (otpSecret.isEmpty()) {
return {};
}
Expand Down Expand Up @@ -246,12 +245,12 @@ void Account::fetchAvatar()
url.setHost(QStringLiteral("na.%1").arg(m_launcher.settings()->mainServer())); // TODO: NA isnt the only thing in the world...
url.setPath(QStringLiteral("/lodestone/character/%1").arg(lodestoneId()));

QNetworkRequest request(url);
const QNetworkRequest request(url);
Utility::printRequest(QStringLiteral("GET"), request);

const auto reply = m_launcher.mgr()->get(request);
connect(reply, &QNetworkReply::finished, [this, filename, reply] {
QString document = QString::fromUtf8(reply->readAll());
const QString document = QString::fromUtf8(reply->readAll());
if (!document.isEmpty()) {
const static QRegularExpression re(
QStringLiteral(R"lit(<div\s[^>]*class=["|']frame__chara__face["|'][^>]*>\s*<img\s[&>]*src=["|']([^"']*))lit"));
Expand All @@ -260,7 +259,7 @@ void Account::fetchAvatar()
if (match.hasCaptured(1)) {
const QString newAvatarUrl = match.captured(1);

const QNetworkRequest avatarRequest = QNetworkRequest(QUrl(newAvatarUrl));
const auto avatarRequest = QNetworkRequest(QUrl(newAvatarUrl));
Utility::printRequest(QStringLiteral("GET"), avatarRequest);

auto avatarReply = m_launcher.mgr()->get(avatarRequest);
Expand Down Expand Up @@ -331,34 +330,36 @@ QCoro::Task<QString> Account::getKeychainValue(const QString &key)
}
}

// ReSharper disable once CppMemberFunctionMayBeConst
// ^ Could be const, but this function shouldn't be considered as such
void Account::updateConfig()
{
auto configDir = getConfigDir().absoluteFilePath(QStringLiteral("FFXIV.cfg"));
const auto configDir = getConfigDir().absoluteFilePath(QStringLiteral("FFXIV.cfg"));

if (!QFile::exists(configDir)) {
return;
}

qInfo(ASTRA_LOG) << "Updating FFXIV.cfg...";

auto configDirStd = configDir.toStdString();
const auto configDirStd = configDir.toStdString();

auto cfgFileBuffer = physis_read_file(configDirStd.c_str());
auto cfgFile = physis_cfg_parse(cfgFileBuffer);
const auto cfgFileBuffer = physis_read_file(configDirStd.c_str());
const auto cfgFile = physis_cfg_parse(cfgFileBuffer);

// Ensure that the opening cutscene movie never plays, since it's broken in most versions of Wine
physis_cfg_set_value(cfgFile, "CutsceneMovieOpening", "1");

auto screenshotDir = m_launcher.settings()->screenshotDir();
const auto screenshotDir = m_launcher.settings()->screenshotDir();
Utility::createPathIfNeeded(screenshotDir);

auto screenshotDirWin = Utility::toWindowsPath(screenshotDir);
auto screenshotDirWinStd = screenshotDirWin.toStdString();
const auto screenshotDirWin = Utility::toWindowsPath(screenshotDir);
const auto screenshotDirWinStd = screenshotDirWin.toStdString();

// Set the screenshot path
physis_cfg_set_value(cfgFile, "ScreenShotDir", screenshotDirWinStd.c_str());

auto buffer = physis_cfg_write(cfgFile);
const auto buffer = physis_cfg_write(cfgFile);

QFile file(configDir);
file.open(QIODevice::WriteOnly);
Expand Down
12 changes: 6 additions & 6 deletions launcher/src/accountmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ void AccountManager::load()
const QString uuid = QString(id).remove("account-"_L1);
qInfo(ASTRA_LOG) << "Loading account" << uuid;

auto account = new Account(m_launcher, uuid, this);
const auto account = new Account(m_launcher, uuid, this);
m_accounts.append(account);
Q_EMIT accountsChanged();
}
Expand All @@ -35,7 +35,7 @@ int AccountManager::rowCount(const QModelIndex &index) const
return static_cast<int>(m_accounts.size());
}

QVariant AccountManager::data(const QModelIndex &index, int role) const
QVariant AccountManager::data(const QModelIndex &index, const int role) const
{
if (!checkIndex(index)) {
return {};
Expand All @@ -54,9 +54,9 @@ QHash<int, QByteArray> AccountManager::roleNames() const
return {{AccountRole, QByteArrayLiteral("account")}};
}

Account *AccountManager::createSquareEnixAccount(const QString &username, int licenseType, bool isFreeTrial)
Account *AccountManager::createSquareEnixAccount(const QString &username, const int licenseType, const bool isFreeTrial)
{
auto account = new Account(m_launcher, QUuid::createUuid().toString(), this);
const auto account = new Account(m_launcher, QUuid::createUuid().toString(), this);
account->setIsSapphire(false);
account->setLicense(static_cast<Account::GameLicense>(licenseType));
account->setIsFreeTrial(isFreeTrial);
Expand All @@ -69,7 +69,7 @@ Account *AccountManager::createSquareEnixAccount(const QString &username, int li

Account *AccountManager::createSapphireAccount(const QString &lobbyUrl, const QString &username)
{
auto account = new Account(m_launcher, QUuid::createUuid().toString(), this);
const auto account = new Account(m_launcher, QUuid::createUuid().toString(), this);
account->setIsSapphire(true);
account->setName(username);
account->setLobbyUrl(lobbyUrl);
Expand All @@ -90,7 +90,7 @@ Account *AccountManager::getByUuid(const QString &uuid) const
return nullptr;
}

bool AccountManager::canDelete(Account *account) const
bool AccountManager::canDelete(const Account *account) const
{
Q_UNUSED(account)
return m_accounts.size() != 1;
Expand Down
Loading

0 comments on commit 27e8169

Please sign in to comment.