1
Fork 0
mirror of https://github.com/redstrate/Astra.git synced 2025-04-20 11:47:46 +00:00

Fix ownership of objects

This commit is contained in:
Joshua Goins 2023-07-30 10:11:14 -04:00
parent 79cd117482
commit 1261abe88c
7 changed files with 46 additions and 46 deletions

View file

@ -58,10 +58,10 @@ public:
bool isFreeTrial() const; bool isFreeTrial() const;
void setIsFreeTrial(bool value); void setIsFreeTrial(bool value);
Q_INVOKABLE QString getPassword() const; Q_INVOKABLE QString getPassword();
void setPassword(const QString &password); void setPassword(const QString &password);
Q_INVOKABLE QString getOTP() const; Q_INVOKABLE QString getOTP();
Q_SIGNALS: Q_SIGNALS:
void nameChanged(); void nameChanged();
@ -81,12 +81,12 @@ private:
/* /*
* Sets a value in the keychain. This function is asynchronous. * 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. * Retrieves a value from the keychain. This function is synchronous.
*/ */
QString getKeychainValue(const QString &key) const; QString getKeychainValue(const QString &key);
AccountConfig m_config; AccountConfig m_config;
QString m_key; QString m_key;

View file

@ -28,6 +28,11 @@ class LoginInformation : public QObject
Q_PROPERTY(Profile *profile MEMBER profile) Q_PROPERTY(Profile *profile MEMBER profile)
public: public:
LoginInformation(QObject *parent = nullptr)
: QObject(parent)
{
}
Profile *profile = nullptr; Profile *profile = nullptr;
QString username, password, oneTimePassword; QString username, password, oneTimePassword;

View file

@ -154,7 +154,7 @@ void Account::setIsFreeTrial(const bool value)
} }
} }
QString Account::getPassword() const QString Account::getPassword()
{ {
return getKeychainValue("password"); return getKeychainValue("password");
} }
@ -164,7 +164,7 @@ void Account::setPassword(const QString &password)
setKeychainValue("password", password); setKeychainValue("password", password);
} }
QString Account::getOTP() const QString Account::getOTP()
{ {
auto otpSecret = getKeychainValue("otp-secret"); 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->setTextData(value);
job->setKey(m_key + "-" + key); job->setKey(m_key + "-" + key);
job->start(); 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->setKey(m_key + "-" + key);
job->start(); job->start();

View file

@ -13,8 +13,8 @@ void AccountManager::load()
auto config = KSharedConfig::openStateConfig(); auto config = KSharedConfig::openStateConfig();
for (const auto &id : config->groupList()) { for (const auto &id : config->groupList()) {
if (id.contains("account-")) { if (id.contains("account-")) {
auto profile = new Account(m_launcher, QString(id).remove("account-"), this); auto account = new Account(m_launcher, QString(id).remove("account-"), this);
m_accounts.append(profile); m_accounts.append(account);
} }
} }
} }

View file

@ -84,7 +84,7 @@ void LauncherCore::beginGameExecutable(const Profile &profile, const LoginAuth &
void LauncherCore::beginVanillaGame(const QString &gameExecutablePath, const Profile &profile, const LoginAuth &auth) 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()); gameProcess->setProcessEnvironment(QProcessEnvironment::systemEnvironment());
auto args = getGameArgs(profile, auth); auto args = getGameArgs(profile, auth);
@ -100,7 +100,7 @@ void LauncherCore::beginDalamudGame(const QString &gameExecutablePath, const Pro
QString dataDir = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation); QString dataDir = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
dataDir = "Z:" + dataDir.replace('/', '\\'); dataDir = "Z:" + dataDir.replace('/', '\\');
auto dalamudProcess = new QProcess(); auto dalamudProcess = new QProcess(this);
QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
env.insert("DALAMUD_RUNTIME", dataDir + "\\DalamudRuntime"); env.insert("DALAMUD_RUNTIME", dataDir + "\\DalamudRuntime");
@ -300,14 +300,13 @@ void LauncherCore::readInitialInformation()
LauncherCore::LauncherCore(bool isSteam) LauncherCore::LauncherCore(bool isSteam)
: m_isSteam(isSteam) : m_isSteam(isSteam)
{ {
mgr = new QNetworkAccessManager(); mgr = new QNetworkAccessManager(this);
sapphireLauncher = new SapphireLauncher(*this); sapphireLauncher = new SapphireLauncher(*this, this);
squareLauncher = new SquareLauncher(*this); squareLauncher = new SquareLauncher(*this, this);
squareBoot = new SquareBoot(*this, *squareLauncher); squareBoot = new SquareBoot(*this, *squareLauncher, this);
// assetUpdater = new AssetUpdater(*this); steamApi = new SteamAPI(*this, this);
steamApi = new SteamAPI(*this); m_profileManager = new ProfileManager(*this, this);
m_profileManager = new ProfileManager(*this); m_accountManager = new AccountManager(*this, this);
m_accountManager = new AccountManager(*this);
#ifdef ENABLE_WATCHDOG #ifdef ENABLE_WATCHDOG
watchdog = new Watchdog(*this); watchdog = new Watchdog(*this);
@ -320,12 +319,12 @@ LauncherCore::LauncherCore(bool isSteam)
bool LauncherCore::checkIfInPath(const QString &program) bool LauncherCore::checkIfInPath(const QString &program)
{ {
// TODO: also check /usr/local/bin, /bin32 etc (basically read $PATH) const auto pathList = qgetenv("PATH").split(':');
const QString directory = "/usr/bin";
QFileInfo fileInfo(directory + "/" + program);
return std::any_of(pathList.cbegin(), pathList.cend(), [program](const QByteArray &path) {
QFileInfo fileInfo(path + "/" + program);
return fileInfo.exists() && fileInfo.isFile(); return fileInfo.exists() && fileInfo.isFile();
});
} }
void LauncherCore::addRegistryKey(const Profile &settings, QString key, QString value, QString data) 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) 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->profile = profile;
loginInformation->username = username; loginInformation->username = username;
loginInformation->password = password; loginInformation->password = password;
@ -441,11 +440,7 @@ void LauncherCore::refreshNews()
url.setPath("/news/headline.json"); url.setPath("/news/headline.json");
url.setQuery(query); url.setQuery(query);
auto request = QNetworkRequest(QString("%1&%2").arg(url.toString(), QString::number(QDateTime::currentMSecsSinceEpoch()))); QNetworkRequest request(QString("%1&%2").arg(url.toString(), QString::number(QDateTime::currentMSecsSinceEpoch())));
// TODO: really?
buildRequest(*profileManager()->getProfile(0), request);
request.setRawHeader("Accept", "application/json, text/plain, */*"); request.setRawHeader("Accept", "application/json, text/plain, */*");
request.setRawHeader("Origin", "https://launcher.finalfantasyxiv.com"); request.setRawHeader("Origin", "https://launcher.finalfantasyxiv.com");
request.setRawHeader("Referer", request.setRawHeader("Referer",
@ -457,7 +452,7 @@ void LauncherCore::refreshNews()
QObject::connect(reply, &QNetworkReply::finished, [this, reply] { QObject::connect(reply, &QNetworkReply::finished, [this, reply] {
auto document = QJsonDocument::fromJson(reply->readAll()); auto document = QJsonDocument::fromJson(reply->readAll());
auto headline = new Headline(); auto headline = new Headline(this);
const auto parseNews = [](QJsonObject object) -> News { const auto parseNews = [](QJsonObject object) -> News {
News news; News news;
@ -563,18 +558,18 @@ void LauncherCore::openOfficialLauncher(Profile *profile)
QString finalArg = encryptGameArg(argJoined); QString finalArg = encryptGameArg(argJoined);
auto launcherProcess = new QProcess(); auto launcherProcess = new QProcess(this);
launchExecutable(*profile, launcherProcess, {profile->gamePath() + "/boot/ffxivlauncher64.exe", finalArg}, false, true); launchExecutable(*profile, launcherProcess, {profile->gamePath() + "/boot/ffxivlauncher64.exe", finalArg}, false, true);
} }
void LauncherCore::openSystemInfo(Profile *profile) void LauncherCore::openSystemInfo(Profile *profile)
{ {
auto sysinfoProcess = new QProcess(); auto sysinfoProcess = new QProcess(this);
launchExecutable(*profile, sysinfoProcess, {profile->gamePath() + "/boot/ffxivsysinfo64.exe"}, false, false); launchExecutable(*profile, sysinfoProcess, {profile->gamePath() + "/boot/ffxivsysinfo64.exe"}, false, false);
} }
void LauncherCore::openConfigBackup(Profile *profile) void LauncherCore::openConfigBackup(Profile *profile)
{ {
auto configProcess = new QProcess(); auto configProcess = new QProcess(this);
launchExecutable(*profile, configProcess, {profile->gamePath() + "/boot/ffxivconfig64.exe"}, false, false); launchExecutable(*profile, configProcess, {profile->gamePath() + "/boot/ffxivconfig64.exe"}, false, false);
} }

View file

@ -22,8 +22,8 @@ void SquareBoot::bootCheck(const LoginInformation &info)
{ {
Q_EMIT window.stageChanged(i18n("Checking for launcher updates...")); Q_EMIT window.stageChanged(i18n("Checking for launcher updates..."));
patcher = new Patcher(info.profile->gamePath() + "/boot", info.profile->bootData); patcher = new Patcher(info.profile->gamePath() + "/boot", info.profile->bootData, this);
connect(patcher, &Patcher::done, [=, &info] { connect(patcher, &Patcher::done, [this, &info] {
info.profile->readGameVersion(); info.profile->readGameVersion();
launcher.getStored(info); launcher.getStored(info);
@ -68,7 +68,7 @@ void SquareBoot::checkGateStatus(LoginInformation *info)
window.buildRequest(*info->profile, request); window.buildRequest(*info->profile, request);
auto reply = window.mgr->get(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 // 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, // 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. // causing the launcher to be stuck in "maintenace mode". so if that happens, we try to rerun this logic.

View file

@ -58,7 +58,7 @@ void SquareLauncher::getStored(const LoginInformation &info)
QNetworkReply *reply = window.mgr->get(request); QNetworkReply *reply = window.mgr->get(request);
connect(reply, &QNetworkReply::finished, [=, &info] { connect(reply, &QNetworkReply::finished, [this, &info, reply, url] {
auto str = QString(reply->readAll()); auto str = QString(reply->readAll());
// fetches Steam username // fetches Steam username
@ -102,7 +102,7 @@ void SquareLauncher::login(const LoginInformation &info, const QUrl &referer)
request.setRawHeader("Cache-Control", "no-cache"); request.setRawHeader("Cache-Control", "no-cache");
auto reply = window.mgr->post(request, postData.toString(QUrl::FullyEncoded).toUtf8()); 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()); auto str = QString(reply->readAll());
QRegularExpression re(R"lit(window.external.user\("login=auth,ok,(?<launchParams>.*)\);)lit"); QRegularExpression re(R"lit(window.external.user\("login=auth,ok,(?<launchParams>.*)\);)lit");
@ -166,13 +166,13 @@ void SquareLauncher::registerSession(const LoginInformation &info)
} }
auto reply = window.mgr->post(request, report.toUtf8()); 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->error() == QNetworkReply::NoError) {
if (reply->rawHeaderList().contains("X-Patch-Unique-Id")) { if (reply->rawHeaderList().contains("X-Patch-Unique-Id")) {
QString body = reply->readAll(); QString body = reply->readAll();
patcher = new Patcher(info.profile->gamePath() + "/game", info.profile->gameData); patcher = new Patcher(info.profile->gamePath() + "/game", info.profile->gameData, this);
connect(patcher, &Patcher::done, [=, &info] { connect(patcher, &Patcher::done, [this, &info, reply] {
info.profile->readGameVersion(); info.profile->readGameVersion();
auth.SID = reply->rawHeader("X-Patch-Unique-Id"); auth.SID = reply->rawHeader("X-Patch-Unique-Id");