diff --git a/src/common/appmanagercommon.cpp b/src/common/appmanagercommon.cpp index 9175bca1fdbf1360284088698e407d5e02a04367..dd3d7456736225d13d54cd0d14bacd250f3eb228 100644 --- a/src/common/appmanagercommon.cpp +++ b/src/common/appmanagercommon.cpp @@ -70,3 +70,8 @@ QString AM::formatBytes(qint64 input, int prec) } return flowValueStr; } + +bool AM::judgePkgIsInstalledFromStr(const QString &str) +{ + return str.contains("installed") && !str.contains("not-installed"); +} diff --git a/src/common/appmanagercommon.h b/src/common/appmanagercommon.h index 25ecb709926c6a12f36ede9d225e9e2e1fd68387..e2e21e11a1459b959a2ce2f424d04391cfda94ab 100644 --- a/src/common/appmanagercommon.h +++ b/src/common/appmanagercommon.h @@ -99,4 +99,6 @@ PinyinInfo getPinYinInfoFromStr(const QString &words); void popupNormalSysNotify(const QString &summary, const QString &body); // 格式化容量 QString formatBytes(qint64 input, int prec); +// 从状态字符串中判断包是否已安装 +bool judgePkgIsInstalledFromStr(const QString &str); } // namespace AM diff --git a/src/job/appmanagerjob.cpp b/src/job/appmanagerjob.cpp index 14bab5f99b5a53e6ff93945b8d5d63de628ddc64..5d2eac2d7e59b52c2ff5383378b4b414e5feed1d 100644 --- a/src/job/appmanagerjob.cpp +++ b/src/job/appmanagerjob.cpp @@ -550,7 +550,7 @@ bool AppManagerJob::getPkgInfoListFromFile(QList &pkgInfoList, const QS } if (lineText.startsWith("Status: ")) { - pkgInfo.isInstalled = lineText.contains("installed"); + pkgInfo.isInstalled = judgePkgIsInstalledFromStr(lineText); continue; } @@ -576,7 +576,7 @@ bool AppManagerJob::getPkgInfoListFromFile(QList &pkgInfoList, const QS } if (lineText.startsWith("Status: ")) { - pkgInfo.isInstalled = lineText.contains("installed"); + pkgInfo.isInstalled = judgePkgIsInstalledFromStr(lineText); pkgInfo.isHoldVersion = lineText.contains("hold"); continue; } @@ -681,7 +681,7 @@ bool AppManagerJob::getInstalledPkgInfo(PkgInfo &pkgInfo, const QString &pkgName } if (lineText.startsWith("Status: ")) { - pkgInfo.isInstalled = lineText.contains("installed"); + pkgInfo.isInstalled = judgePkgIsInstalledFromStr(lineText); pkgInfo.isHoldVersion = lineText.contains("hold"); continue; } diff --git a/src/pkgmonitor/pkgmonitor.cpp b/src/pkgmonitor/pkgmonitor.cpp index bb709e93f5c963f2e4d9347d7311824f830c47cb..08c30ad3e286e44e08463b62f540e5e8708367e0 100644 --- a/src/pkgmonitor/pkgmonitor.cpp +++ b/src/pkgmonitor/pkgmonitor.cpp @@ -171,7 +171,7 @@ QSet PkgMonitor::getCurrentInstalledPkgNameSet() const } if (lineText.startsWith("Status: ")) { - isInstalled = lineText.contains("installed"); + isInstalled = AM::judgePkgIsInstalledFromStr(lineText); continue; } diff --git a/src/pkgmonitor/pkgmonitor.h b/src/pkgmonitor/pkgmonitor.h index 59f8f3c6e182ffe0d4ef24927030b937af13c864..9eb01d1b8999797c2441f3edb1c52f6577228a05 100644 --- a/src/pkgmonitor/pkgmonitor.h +++ b/src/pkgmonitor/pkgmonitor.h @@ -1,5 +1,7 @@ #pragma once +#include "../common/appmanagercommon.h" + #include #include #include