diff --git a/appmanagercommon.h b/appmanagercommon.h index d962919073e6fd9312782bceaf6616e3101fb8a0..fd5aa1c181a89eacb18dc4c1c809272d7070a4d2 100644 --- a/appmanagercommon.h +++ b/appmanagercommon.h @@ -16,6 +16,7 @@ struct PkgInfo { qint64 contentSize; // 内容大小 QString depositoryUrl; // 仓库地址 QString pkgName; + bool isInstalled; int installedSize; QString updatedTime; QString maintainer; @@ -32,6 +33,7 @@ struct PkgInfo { contentOffset = 0; contentSize = 0; installedSize = 0; + isInstalled = false; pkgSize = 0; } }; diff --git a/appmanagerjob.cpp b/appmanagerjob.cpp index c1147c54aae698277090b475e397224119d740d6..ee2efd294917ae4ef84b27d625fc2930bb183935 100644 --- a/appmanagerjob.cpp +++ b/appmanagerjob.cpp @@ -527,7 +527,6 @@ bool AppManagerJob::getPkgInfoListFromFile(QList &pkgInfoList, const QS } PkgInfo pkgInfo; - bool isInstalled = false; bool isReadingDescription = false; // 是否获取简洁信息 if (isCompact) { @@ -544,7 +543,7 @@ bool AppManagerJob::getPkgInfoListFromFile(QList &pkgInfoList, const QS } if (lineText.startsWith("Status: ")) { - isInstalled = lineText.split(": ").last().startsWith("install"); + pkgInfo.isInstalled = lineText.split(": ").last().startsWith("install"); continue; } @@ -555,9 +554,7 @@ bool AppManagerJob::getPkgInfoListFromFile(QList &pkgInfoList, const QS pkgInfo.contentOffset = contentOffset; pkgInfo.contentSize = contentOffset - lastPkgContentOffset; lastPkgContentOffset = contentOffset; - if (isInstalled) { - pkgInfoList.append(pkgInfo); - } + pkgInfoList.append(pkgInfo); pkgInfo = {}; } } @@ -572,7 +569,7 @@ bool AppManagerJob::getPkgInfoListFromFile(QList &pkgInfoList, const QS } if (lineText.startsWith("Status: ")) { - isInstalled = lineText.split(": ").last().startsWith("install"); + pkgInfo.isInstalled = lineText.split(": ").last().startsWith("install"); continue; } @@ -631,9 +628,7 @@ bool AppManagerJob::getPkgInfoListFromFile(QList &pkgInfoList, const QS if (lineText.isEmpty()) { pkgInfo.infosFilePath = pkgInfosFilePath; pkgInfo.depositoryUrl = depositoryUrlStr; - if (isInstalled) { - pkgInfoList.append(pkgInfo); - } + pkgInfoList.append(pkgInfo); pkgInfo = {}; } } @@ -643,9 +638,7 @@ bool AppManagerJob::getPkgInfoListFromFile(QList &pkgInfoList, const QS // 判断循环中最后一个包信息是否没添加到列表 // 防止最后一个包信息的最后一行不是换行符,而忽略了该包信息 if (!pkgInfo.pkgName.isEmpty()) { - if (isInstalled) { - pkgInfoList.append(pkgInfo); - } + pkgInfoList.append(pkgInfo); } qInfo() << Q_FUNC_INFO << "end"; @@ -661,7 +654,6 @@ bool AppManagerJob::getInstalledPkgInfo(PkgInfo &pkgInfo, const QString &pkgName return false; } - bool isInstalled = false; bool isReadingDescription = false; while (!file.atEnd()) { const QByteArray ba = file.readLine(); @@ -681,7 +673,7 @@ bool AppManagerJob::getInstalledPkgInfo(PkgInfo &pkgInfo, const QString &pkgName } if (lineText.startsWith("Status: ")) { - isInstalled = lineText.split(": ").last().startsWith("install"); + pkgInfo.isInstalled = lineText.split(": ").last().startsWith("install"); continue; } @@ -739,7 +731,7 @@ bool AppManagerJob::getInstalledPkgInfo(PkgInfo &pkgInfo, const QString &pkgName if (lineText.isEmpty()) { pkgInfo.infosFilePath = localPkgInfosFilePath; if (pkgName == pkgInfo.pkgName) { - if (isInstalled) { + if (pkgInfo.isInstalled) { break; } } @@ -794,6 +786,9 @@ void AppManagerJob::loadAllPkgInstalledAppInfos() getPkgInfoListFromFile(pkgInfoList, "/var/lib/dpkg/status"); for (const PkgInfo &pkgInfo : pkgInfoList) { + if (!pkgInfo.isInstalled) { + continue; + } loadPkgInstalledAppInfo(pkgInfo); } }