mirror of
https://invent.kde.org/marcoa/a-la-karte.git
synced 2026-03-27 01:03:09 +00:00
Use KDesktopFile/KConfigGroup to parse .desktop files reliably. This avoids Categories parsing pitfalls and improves detection of KDE stock games. Centralize game-category matching and use stable IDs based on the full desktop-file basename.
74 lines
2.6 KiB
C++
74 lines
2.6 KiB
C++
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
// SPDX-FileCopyrightText: 2024 A-La-Karte Contributors
|
|
|
|
#include "platformimporter.h"
|
|
|
|
#include <QDir>
|
|
#include <QRegularExpression>
|
|
#include <QStandardPaths>
|
|
|
|
PlatformImporter::PlatformImporter(QObject *parent)
|
|
: QObject(parent)
|
|
{
|
|
}
|
|
|
|
QString PlatformImporter::findExecutable(const QString &name) const
|
|
{
|
|
return QStandardPaths::findExecutable(name);
|
|
}
|
|
|
|
bool PlatformImporter::directoryExists(const QString &path) const
|
|
{
|
|
return QDir(expandPath(path)).exists();
|
|
}
|
|
|
|
QString PlatformImporter::expandPath(const QString &path) const
|
|
{
|
|
QString result = path;
|
|
|
|
// Expand ~ to home directory
|
|
if (result.startsWith(QLatin1Char('~'))) {
|
|
result.replace(0, 1, QDir::homePath());
|
|
}
|
|
|
|
// Expand environment variables
|
|
static QRegularExpression envVarRegex(QStringLiteral("\\$\\{?([A-Za-z_][A-Za-z0-9_]*)\\}?"));
|
|
QRegularExpressionMatchIterator it = envVarRegex.globalMatch(result);
|
|
|
|
while (it.hasNext()) {
|
|
QRegularExpressionMatch match = it.next();
|
|
QString varName = match.captured(1);
|
|
QString varValue = QString::fromLocal8Bit(qgetenv(varName.toLocal8Bit().constData()));
|
|
result.replace(match.captured(0), varValue);
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
bool PlatformImporter::hasGameCategory(const QStringList &categories)
|
|
{
|
|
static const QStringList gameCategories = {QStringLiteral("Game"),
|
|
QStringLiteral("ArcadeGame"),
|
|
QStringLiteral("ActionGame"),
|
|
QStringLiteral("AdventureGame"),
|
|
QStringLiteral("BlocksGame"),
|
|
QStringLiteral("BoardGame"),
|
|
QStringLiteral("CardGame"),
|
|
QStringLiteral("KidsGame"),
|
|
QStringLiteral("LogicGame"),
|
|
QStringLiteral("RolePlaying"),
|
|
QStringLiteral("Shooter"),
|
|
QStringLiteral("Simulation"),
|
|
QStringLiteral("SportsGame"),
|
|
QStringLiteral("StrategyGame")};
|
|
|
|
for (const QString &category : categories) {
|
|
for (const QString &cat : gameCategories) {
|
|
if (category.compare(cat, Qt::CaseInsensitive) == 0) {
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|