2023-08-05 22:14:05 -04:00
|
|
|
// SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.com>
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2023-07-30 08:49:34 -04:00
|
|
|
#include "profilemanager.h"
|
2023-10-08 18:02:02 -04:00
|
|
|
#include "astra_log.h"
|
2023-07-30 08:49:34 -04:00
|
|
|
|
2023-08-18 12:59:07 -04:00
|
|
|
#include <KSharedConfig>
|
2023-07-30 08:49:34 -04:00
|
|
|
#include <QDir>
|
2023-08-18 12:59:07 -04:00
|
|
|
#include <QUuid>
|
2023-07-30 08:49:34 -04:00
|
|
|
|
|
|
|
ProfileManager::ProfileManager(LauncherCore &launcher, QObject *parent)
|
|
|
|
: QAbstractListModel(parent)
|
|
|
|
, m_launcher(launcher)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Profile *ProfileManager::getProfile(const int index)
|
|
|
|
{
|
|
|
|
return m_profiles[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
int ProfileManager::getProfileIndex(const QString &name)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < m_profiles.size(); i++) {
|
2023-10-08 20:01:17 -04:00
|
|
|
if (m_profiles[i]->uuid() == name)
|
2023-07-30 08:49:34 -04:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2023-09-17 19:20:41 -04:00
|
|
|
Profile *ProfileManager::getProfileByUUID(const QString &uuid)
|
|
|
|
{
|
|
|
|
for (auto &m_profile : m_profiles) {
|
|
|
|
if (m_profile->uuid() == uuid)
|
|
|
|
return m_profile;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2023-07-30 08:49:34 -04:00
|
|
|
Profile *ProfileManager::addProfile()
|
|
|
|
{
|
|
|
|
auto newProfile = new Profile(m_launcher, QUuid::createUuid().toString(), this);
|
2023-09-17 08:52:48 -04:00
|
|
|
newProfile->setName(QStringLiteral("New Profile"));
|
2023-07-30 08:49:34 -04:00
|
|
|
|
|
|
|
insertProfile(newProfile);
|
|
|
|
|
|
|
|
return newProfile;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProfileManager::deleteProfile(Profile *profile)
|
|
|
|
{
|
|
|
|
auto config = KSharedConfig::openStateConfig();
|
2023-09-17 08:52:48 -04:00
|
|
|
config->deleteGroup(QStringLiteral("profile-%1").arg(profile->uuid()));
|
2023-07-30 08:49:34 -04:00
|
|
|
config->sync();
|
|
|
|
|
2023-09-17 09:02:11 -04:00
|
|
|
const int row = static_cast<int>(m_profiles.indexOf(profile));
|
2023-07-30 08:49:34 -04:00
|
|
|
beginRemoveRows(QModelIndex(), row, row);
|
|
|
|
m_profiles.removeAll(profile);
|
|
|
|
endRemoveRows();
|
|
|
|
}
|
|
|
|
|
2023-08-18 14:52:06 -04:00
|
|
|
QString ProfileManager::getDefaultGamePath(const QString &uuid)
|
2023-07-30 08:49:34 -04:00
|
|
|
{
|
|
|
|
#if defined(Q_OS_WIN)
|
|
|
|
return "C:\\Program Files (x86)\\SquareEnix\\FINAL FANTASY XIV - A Realm Reborn";
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(Q_OS_MAC)
|
|
|
|
return QDir::homePath() +
|
|
|
|
"/Library/Application Support/FINAL FANTASY XIV ONLINE/Bottles/published_Final_Fantasy/drive_c/Program "
|
|
|
|
"Files (x86)/SquareEnix/FINAL FANTASY XIV - A Realm Reborn";
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(Q_OS_LINUX)
|
2023-08-18 14:52:06 -04:00
|
|
|
const QDir appData = QStandardPaths::standardLocations(QStandardPaths::StandardLocation::AppDataLocation)[0];
|
2023-09-17 08:52:48 -04:00
|
|
|
const QDir gameDir = appData.absoluteFilePath(QStringLiteral("game"));
|
2023-08-18 14:52:06 -04:00
|
|
|
return gameDir.absoluteFilePath(uuid);
|
2023-07-30 08:49:34 -04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2023-10-08 18:15:41 -04:00
|
|
|
QString ProfileManager::getDefaultWinePrefixPath(const QString &uuid)
|
|
|
|
{
|
|
|
|
const QDir appData = QStandardPaths::standardLocations(QStandardPaths::StandardLocation::AppDataLocation)[0];
|
|
|
|
const QDir prefixDir = appData.absoluteFilePath(QStringLiteral("prefix"));
|
|
|
|
return prefixDir.absoluteFilePath(uuid);
|
|
|
|
}
|
|
|
|
|
2023-07-30 08:49:34 -04:00
|
|
|
void ProfileManager::load()
|
|
|
|
{
|
|
|
|
auto config = KSharedConfig::openStateConfig();
|
|
|
|
for (const auto &id : config->groupList()) {
|
2023-09-17 08:52:48 -04:00
|
|
|
if (id.contains(QLatin1String("profile-"))) {
|
2023-10-08 18:02:02 -04:00
|
|
|
const QString uuid = QString(id).remove(QLatin1String("profile-"));
|
|
|
|
qInfo(ASTRA_LOG) << "Loading profile" << uuid;
|
|
|
|
auto profile = new Profile(m_launcher, uuid, this);
|
2023-07-30 08:49:34 -04:00
|
|
|
insertProfile(profile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add a dummy profile if none exist
|
|
|
|
if (m_profiles.empty()) {
|
|
|
|
addProfile();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int ProfileManager::rowCount(const QModelIndex &index) const
|
|
|
|
{
|
2023-12-17 10:27:07 -05:00
|
|
|
Q_UNUSED(index)
|
2023-09-17 09:02:11 -04:00
|
|
|
return static_cast<int>(m_profiles.size());
|
2023-07-30 08:49:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
QVariant ProfileManager::data(const QModelIndex &index, int role) const
|
|
|
|
{
|
|
|
|
if (!checkIndex(index)) {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
const int row = index.row();
|
|
|
|
if (role == ProfileRole) {
|
|
|
|
return QVariant::fromValue(m_profiles[row]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
QHash<int, QByteArray> ProfileManager::roleNames() const
|
|
|
|
{
|
|
|
|
return {{ProfileRole, QByteArrayLiteral("profile")}};
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProfileManager::insertProfile(Profile *profile)
|
|
|
|
{
|
2023-09-17 09:02:11 -04:00
|
|
|
beginInsertRows(QModelIndex(), static_cast<int>(m_profiles.size()), static_cast<int>(m_profiles.size()));
|
2023-07-30 08:49:34 -04:00
|
|
|
m_profiles.append(profile);
|
|
|
|
endInsertRows();
|
|
|
|
}
|
|
|
|
|
2023-12-17 11:07:34 -05:00
|
|
|
QList<Profile *> ProfileManager::profiles() const
|
2023-07-30 08:49:34 -04:00
|
|
|
{
|
|
|
|
return m_profiles;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ProfileManager::canDelete(Profile *account) const
|
|
|
|
{
|
|
|
|
Q_UNUSED(account)
|
|
|
|
return m_profiles.size() != 1;
|
|
|
|
}
|
2023-10-08 20:01:17 -04:00
|
|
|
|
|
|
|
bool ProfileManager::hasAnyExistingInstallations() const
|
|
|
|
{
|
|
|
|
for (auto &profile : m_profiles) {
|
|
|
|
if (profile->isGameInstalled()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2023-10-08 20:24:35 -04:00
|
|
|
|
|
|
|
int ProfileManager::numProfiles() const
|
|
|
|
{
|
|
|
|
return m_profiles.count();
|
|
|
|
}
|
2023-12-17 11:12:13 -05:00
|
|
|
|
|
|
|
#include "moc_profilemanager.cpp"
|