diff --git a/launcher/include/account.h b/launcher/include/account.h index 57c8d07..ceb75ce 100644 --- a/launcher/include/account.h +++ b/launcher/include/account.h @@ -58,10 +58,10 @@ public: bool isFreeTrial() const; void setIsFreeTrial(bool value); - Q_INVOKABLE QString getPassword() const; + Q_INVOKABLE QString getPassword(); void setPassword(const QString &password); - Q_INVOKABLE QString getOTP() const; + Q_INVOKABLE QString getOTP(); Q_SIGNALS: void nameChanged(); @@ -81,12 +81,12 @@ private: /* * Sets a value in the keychain. This function is asynchronous. */ - void setKeychainValue(const QString &key, const QString &value) const; + void setKeychainValue(const QString &key, const QString &value); /* * Retrieves a value from the keychain. This function is synchronous. */ - QString getKeychainValue(const QString &key) const; + QString getKeychainValue(const QString &key); AccountConfig m_config; QString m_key; diff --git a/launcher/include/launchercore.h b/launcher/include/launchercore.h index af27af4..1bfe5c7 100755 --- a/launcher/include/launchercore.h +++ b/launcher/include/launchercore.h @@ -28,6 +28,11 @@ class LoginInformation : public QObject Q_PROPERTY(Profile *profile MEMBER profile) public: + LoginInformation(QObject *parent = nullptr) + : QObject(parent) + { + } + Profile *profile = nullptr; QString username, password, oneTimePassword; diff --git a/launcher/src/account.cpp b/launcher/src/account.cpp index 109c55b..3cd69cc 100644 --- a/launcher/src/account.cpp +++ b/launcher/src/account.cpp @@ -154,7 +154,7 @@ void Account::setIsFreeTrial(const bool value) } } -QString Account::getPassword() const +QString Account::getPassword() { return getKeychainValue("password"); } @@ -164,7 +164,7 @@ void Account::setPassword(const QString &password) setKeychainValue("password", password); } -QString Account::getOTP() const +QString Account::getOTP() { auto otpSecret = getKeychainValue("otp-secret"); @@ -192,19 +192,19 @@ void Account::fetchAvatar() }); } -void Account::setKeychainValue(const QString &key, const QString &value) const +void Account::setKeychainValue(const QString &key, const QString &value) { - auto job = new QKeychain::WritePasswordJob("Astra"); + auto job = new QKeychain::WritePasswordJob("Astra", this); job->setTextData(value); job->setKey(m_key + "-" + key); job->start(); } -QString Account::getKeychainValue(const QString &key) const +QString Account::getKeychainValue(const QString &key) { - auto loop = new QEventLoop(); + auto loop = new QEventLoop(this); - auto job = new QKeychain::ReadPasswordJob("Astra"); + auto job = new QKeychain::ReadPasswordJob("Astra", this); job->setKey(m_key + "-" + key); job->start(); diff --git a/launcher/src/accountmanager.cpp b/launcher/src/accountmanager.cpp index f16f8aa..5f13765 100644 --- a/launcher/src/accountmanager.cpp +++ b/launcher/src/accountmanager.cpp @@ -13,8 +13,8 @@ void AccountManager::load() auto config = KSharedConfig::openStateConfig(); for (const auto &id : config->groupList()) { if (id.contains("account-")) { - auto profile = new Account(m_launcher, QString(id).remove("account-"), this); - m_accounts.append(profile); + auto account = new Account(m_launcher, QString(id).remove("account-"), this); + m_accounts.append(account); } } } diff --git a/launcher/src/launchercore.cpp b/launcher/src/launchercore.cpp index 7207b3d..f19e877 100755 --- a/launcher/src/launchercore.cpp +++ b/launcher/src/launchercore.cpp @@ -84,7 +84,7 @@ void LauncherCore::beginGameExecutable(const Profile &profile, const LoginAuth & void LauncherCore::beginVanillaGame(const QString &gameExecutablePath, const Profile &profile, const LoginAuth &auth) { - auto gameProcess = new QProcess(); + auto gameProcess = new QProcess(this); gameProcess->setProcessEnvironment(QProcessEnvironment::systemEnvironment()); auto args = getGameArgs(profile, auth); @@ -100,7 +100,7 @@ void LauncherCore::beginDalamudGame(const QString &gameExecutablePath, const Pro QString dataDir = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation); dataDir = "Z:" + dataDir.replace('/', '\\'); - auto dalamudProcess = new QProcess(); + auto dalamudProcess = new QProcess(this); QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); env.insert("DALAMUD_RUNTIME", dataDir + "\\DalamudRuntime"); @@ -300,14 +300,13 @@ void LauncherCore::readInitialInformation() LauncherCore::LauncherCore(bool isSteam) : m_isSteam(isSteam) { - mgr = new QNetworkAccessManager(); - sapphireLauncher = new SapphireLauncher(*this); - squareLauncher = new SquareLauncher(*this); - squareBoot = new SquareBoot(*this, *squareLauncher); - // assetUpdater = new AssetUpdater(*this); - steamApi = new SteamAPI(*this); - m_profileManager = new ProfileManager(*this); - m_accountManager = new AccountManager(*this); + mgr = new QNetworkAccessManager(this); + sapphireLauncher = new SapphireLauncher(*this, this); + squareLauncher = new SquareLauncher(*this, this); + squareBoot = new SquareBoot(*this, *squareLauncher, this); + steamApi = new SteamAPI(*this, this); + m_profileManager = new ProfileManager(*this, this); + m_accountManager = new AccountManager(*this, this); #ifdef ENABLE_WATCHDOG watchdog = new Watchdog(*this); @@ -320,12 +319,12 @@ LauncherCore::LauncherCore(bool isSteam) bool LauncherCore::checkIfInPath(const QString &program) { - // TODO: also check /usr/local/bin, /bin32 etc (basically read $PATH) - const QString directory = "/usr/bin"; + const auto pathList = qgetenv("PATH").split(':'); - QFileInfo fileInfo(directory + "/" + program); - - return fileInfo.exists() && fileInfo.isFile(); + return std::any_of(pathList.cbegin(), pathList.cend(), [program](const QByteArray &path) { + QFileInfo fileInfo(path + "/" + program); + return fileInfo.exists() && fileInfo.isFile(); + }); } void LauncherCore::addRegistryKey(const Profile &settings, QString key, QString value, QString data) @@ -337,7 +336,7 @@ void LauncherCore::addRegistryKey(const Profile &settings, QString key, QString void LauncherCore::login(Profile *profile, const QString &username, const QString &password, const QString &oneTimePassword) { - auto loginInformation = new LoginInformation(); + auto loginInformation = new LoginInformation(this); loginInformation->profile = profile; loginInformation->username = username; loginInformation->password = password; @@ -441,11 +440,7 @@ void LauncherCore::refreshNews() url.setPath("/news/headline.json"); url.setQuery(query); - auto request = QNetworkRequest(QString("%1&%2").arg(url.toString(), QString::number(QDateTime::currentMSecsSinceEpoch()))); - - // TODO: really? - buildRequest(*profileManager()->getProfile(0), request); - + QNetworkRequest request(QString("%1&%2").arg(url.toString(), QString::number(QDateTime::currentMSecsSinceEpoch()))); request.setRawHeader("Accept", "application/json, text/plain, */*"); request.setRawHeader("Origin", "https://launcher.finalfantasyxiv.com"); request.setRawHeader("Referer", @@ -457,7 +452,7 @@ void LauncherCore::refreshNews() QObject::connect(reply, &QNetworkReply::finished, [this, reply] { auto document = QJsonDocument::fromJson(reply->readAll()); - auto headline = new Headline(); + auto headline = new Headline(this); const auto parseNews = [](QJsonObject object) -> News { News news; @@ -563,18 +558,18 @@ void LauncherCore::openOfficialLauncher(Profile *profile) QString finalArg = encryptGameArg(argJoined); - auto launcherProcess = new QProcess(); + auto launcherProcess = new QProcess(this); launchExecutable(*profile, launcherProcess, {profile->gamePath() + "/boot/ffxivlauncher64.exe", finalArg}, false, true); } void LauncherCore::openSystemInfo(Profile *profile) { - auto sysinfoProcess = new QProcess(); + auto sysinfoProcess = new QProcess(this); launchExecutable(*profile, sysinfoProcess, {profile->gamePath() + "/boot/ffxivsysinfo64.exe"}, false, false); } void LauncherCore::openConfigBackup(Profile *profile) { - auto configProcess = new QProcess(); + auto configProcess = new QProcess(this); launchExecutable(*profile, configProcess, {profile->gamePath() + "/boot/ffxivconfig64.exe"}, false, false); } diff --git a/launcher/src/squareboot.cpp b/launcher/src/squareboot.cpp index 377aba6..99614ab 100644 --- a/launcher/src/squareboot.cpp +++ b/launcher/src/squareboot.cpp @@ -22,8 +22,8 @@ void SquareBoot::bootCheck(const LoginInformation &info) { Q_EMIT window.stageChanged(i18n("Checking for launcher updates...")); - patcher = new Patcher(info.profile->gamePath() + "/boot", info.profile->bootData); - connect(patcher, &Patcher::done, [=, &info] { + patcher = new Patcher(info.profile->gamePath() + "/boot", info.profile->bootData, this); + connect(patcher, &Patcher::done, [this, &info] { info.profile->readGameVersion(); launcher.getStored(info); @@ -68,7 +68,7 @@ void SquareBoot::checkGateStatus(LoginInformation *info) window.buildRequest(*info->profile, request); auto reply = window.mgr->get(request); - connect(reply, &QNetworkReply::finished, [=] { + connect(reply, &QNetworkReply::finished, [this, reply, info] { // I happen to run into this issue often, if I start the launcher really quickly after bootup // it's possible to actually check this quicker than the network is actually available, // causing the launcher to be stuck in "maintenace mode". so if that happens, we try to rerun this logic. diff --git a/launcher/src/squarelauncher.cpp b/launcher/src/squarelauncher.cpp index 53de690..41ca6eb 100644 --- a/launcher/src/squarelauncher.cpp +++ b/launcher/src/squarelauncher.cpp @@ -58,7 +58,7 @@ void SquareLauncher::getStored(const LoginInformation &info) QNetworkReply *reply = window.mgr->get(request); - connect(reply, &QNetworkReply::finished, [=, &info] { + connect(reply, &QNetworkReply::finished, [this, &info, reply, url] { auto str = QString(reply->readAll()); // fetches Steam username @@ -102,7 +102,7 @@ void SquareLauncher::login(const LoginInformation &info, const QUrl &referer) request.setRawHeader("Cache-Control", "no-cache"); auto reply = window.mgr->post(request, postData.toString(QUrl::FullyEncoded).toUtf8()); - connect(reply, &QNetworkReply::finished, [=, &info] { + connect(reply, &QNetworkReply::finished, [this, &info, reply] { auto str = QString(reply->readAll()); QRegularExpression re(R"lit(window.external.user\("login=auth,ok,(?.*)\);)lit"); @@ -166,13 +166,13 @@ void SquareLauncher::registerSession(const LoginInformation &info) } auto reply = window.mgr->post(request, report.toUtf8()); - connect(reply, &QNetworkReply::finished, [=, &info] { + connect(reply, &QNetworkReply::finished, [this, &info, reply] { if (reply->error() == QNetworkReply::NoError) { if (reply->rawHeaderList().contains("X-Patch-Unique-Id")) { QString body = reply->readAll(); - patcher = new Patcher(info.profile->gamePath() + "/game", info.profile->gameData); - connect(patcher, &Patcher::done, [=, &info] { + patcher = new Patcher(info.profile->gamePath() + "/game", info.profile->gameData, this); + connect(patcher, &Patcher::done, [this, &info, reply] { info.profile->readGameVersion(); auth.SID = reply->rawHeader("X-Patch-Unique-Id");