mirror of
https://gitee.com/spark-store-project/spark-store
synced 2025-12-15 05:12:04 +08:00
fix:修正了无软件名时,软件名内容为空的问题
This commit is contained in:
@@ -76,32 +76,44 @@ QStringList aptssUpdater::getDesktopAppNames()
|
|||||||
|
|
||||||
foreach (const QString &package, packages) {
|
foreach (const QString &package, packages) {
|
||||||
QString packageName = package.split(":")[0];
|
QString packageName = package.split(":")[0];
|
||||||
|
QString finalName = packageName; // 默认使用包名
|
||||||
|
|
||||||
// 获取包文件列表
|
// 获取包文件列表
|
||||||
dpkgProcess.start("dpkg", QStringList() << "-L" << packageName);
|
dpkgProcess.start("dpkg", QStringList() << "-L" << packageName);
|
||||||
dpkgProcess.waitForFinished();
|
dpkgProcess.waitForFinished();
|
||||||
QStringList files = QString(dpkgProcess.readAllStandardOutput()).split('\n', Qt::SkipEmptyParts);
|
QStringList files = QString(dpkgProcess.readAllStandardOutput()).split('\n', Qt::SkipEmptyParts);
|
||||||
|
|
||||||
// 检查常规应用目录
|
// 先检查常规应用目录
|
||||||
checkDesktopFiles(files.filter("/usr/share/applications/"),
|
QStringList regularDesktopFiles = files.filter("/usr/share/applications/");
|
||||||
appNames,
|
QString regularAppName;
|
||||||
lang,
|
if (!regularDesktopFiles.isEmpty()) {
|
||||||
packageName); // 新增包名参数
|
checkDesktopFiles(regularDesktopFiles, regularAppName, lang, packageName);
|
||||||
|
}
|
||||||
|
|
||||||
// 检查特殊目录(/opt/apps)
|
// 如果常规目录没有找到,再检查特殊目录
|
||||||
checkDesktopFiles(files.filter(QRegularExpression(QString("/opt/apps/%1/entries/applications").arg(packageName))),
|
if (regularAppName.isEmpty()) {
|
||||||
appNames,
|
QStringList specialDesktopFiles = files.filter(QRegularExpression(QString("/opt/apps/%1/entries/applications").arg(packageName)));
|
||||||
lang,
|
QString specialAppName;
|
||||||
packageName); // 新增包名参数
|
if (!specialDesktopFiles.isEmpty()) {
|
||||||
|
checkDesktopFiles(specialDesktopFiles, specialAppName, lang, packageName);
|
||||||
|
if (!specialAppName.isEmpty()) {
|
||||||
|
finalName = specialAppName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
finalName = regularAppName;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 输出格式为[软件名|包名]
|
||||||
|
appNames << QString("[%1|%2]").arg(finalName, packageName);
|
||||||
}
|
}
|
||||||
qDebug()<< "应用名称列表:" << appNames;
|
qDebug()<< "应用名称列表:" << appNames;
|
||||||
return appNames;
|
return appNames;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool aptssUpdater::checkDesktopFiles(const QStringList &desktopFiles, QStringList &appNames, const QString &lang, const QString &packageName)
|
|
||||||
|
bool aptssUpdater::checkDesktopFiles(const QStringList &desktopFiles, QString &appName, const QString &lang, const QString &packageName)
|
||||||
{
|
{
|
||||||
bool hasFoundName = false;
|
|
||||||
QString lastValidName;
|
QString lastValidName;
|
||||||
QRegularExpression noDisplayRe("^NoDisplay=(true|True)");
|
QRegularExpression noDisplayRe("^NoDisplay=(true|True)");
|
||||||
QRegularExpression nameRe("^Name\\[?" + lang + "?\\]?=(.*)");
|
QRegularExpression nameRe("^Name\\[?" + lang + "?\\]?=(.*)");
|
||||||
@@ -145,21 +157,17 @@ bool aptssUpdater::checkDesktopFiles(const QStringList &desktopFiles, QStringLis
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!skip && !currentName.isEmpty()) {
|
if (!skip && !currentName.isEmpty()) {
|
||||||
lastValidName = currentName; // 只更新最后一个有效名称
|
lastValidName = currentName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 处理最终的有效名称
|
// 处理最终的有效名称
|
||||||
if (!lastValidName.isEmpty()) {
|
if (!lastValidName.isEmpty()) {
|
||||||
if (!appNames.contains(lastValidName)) {
|
appName = lastValidName; // 直接赋值而不是使用<<
|
||||||
appNames << lastValidName;
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 回退到包名
|
// 回退到包名
|
||||||
if (!appNames.contains(packageName)) {
|
appName = packageName;
|
||||||
appNames << packageName;
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,11 +18,7 @@ public:
|
|||||||
QString m_tempFilePath;
|
QString m_tempFilePath;
|
||||||
signals:
|
signals:
|
||||||
private:
|
private:
|
||||||
bool checkDesktopFiles(const QStringList &desktopFiles,
|
bool checkDesktopFiles(const QStringList &desktopFiles, QString &appName, const QString &lang, const QString &packageName);
|
||||||
QStringList &appNames,
|
|
||||||
const QString &lang,
|
|
||||||
const QString &packageName); // 新增包名参数
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // APTSSUPDATER_H
|
#endif // APTSSUPDATER_H
|
||||||
Reference in New Issue
Block a user