Skip to content

Commit

Permalink
refactor: update the installer dbus interface
Browse files Browse the repository at this point in the history
Update installer DBus interface to support uab package.

Log: The DBus interface supports uab package.
Influence: uab-package
  • Loading branch information
rb-union committed Sep 26, 2024
1 parent f450991 commit 50608f9
Show file tree
Hide file tree
Showing 23 changed files with 451 additions and 179 deletions.
4 changes: 2 additions & 2 deletions src/deb-installer/manager/packagesmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ bool PackagesManager::dependencyVersionMatch(const int result, const RelationTyp
}
}

int PackagesManager::checkInstallStatus(const QString &package_path)
Pkg::PackageInstallStatus PackagesManager::checkInstallStatus(const QString &package_path)
{
DebFile debFile(package_path);
if (!debFile.isValid())
Expand All @@ -129,7 +129,7 @@ int PackagesManager::checkInstallStatus(const QString &package_path)
const QString packageVersion = debFile.version();
const int result = Package::compareVersion(packageVersion, installedVersion);

int ret;
Pkg::PackageInstallStatus ret = Pkg::NotInstalled;
if (result == 0)
ret = Pkg::PackageInstallStatus::InstalledSameVersion;
else if (result < 0)
Expand Down
2 changes: 1 addition & 1 deletion src/deb-installer/manager/packagesmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class PackagesManager : public QObject
* @brief searchPackageInstallInfo 查找指定包安装状态
* @param package_path 路径
*/
int checkInstallStatus(const QString &package_path);
Pkg::PackageInstallStatus checkInstallStatus(const QString &package_path);
/**
* @brief searchPackageInstallInfo 查找指定包依赖
* @param package_path 包名字
Expand Down
20 changes: 10 additions & 10 deletions src/deb-installer/model/abstract_package_list_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,6 @@ class AbstractPackageListModel : public QAbstractListModel
VerifyDependsErr, // signature verification failed (hierarchical verify)
};

// Signature fail error code
enum ErrorCode {
NoDigitalSignature = 101,
DigitalSignatureError,
ConfigAuthCancel = 127, // Authentication failed
ApplocationProhibit = 404, // the current package is in the blacklist and is prohibited from installation
};

explicit AbstractPackageListModel(QObject *parent = nullptr);

[[nodiscard]] inline Pkg::PackageType supportPackage() const { return m_supportPackageType; }
Expand All @@ -76,9 +68,17 @@ class AbstractPackageListModel : public QAbstractListModel
virtual void removePackage(int index) = 0;
virtual QString checkPackageValid(const QString &packagePath) = 0;

// package base info
virtual Pkg::PackageInstallStatus checkInstallStatus(const QString &packagePath) = 0;
virtual Pkg::DependsStatus checkDependsStatus(const QString &packagePath) = 0;
virtual QStringList getPackageInfo(const QString &packagePath) = 0;

// raw output of install/uninstall failures
virtual QString lastProcessError() = 0;

// trigger install / uninstall
Q_SLOT virtual void slotInstallPackages() = 0;
Q_SLOT virtual void slotUninstallPackage(int index) = 0;
Q_SLOT virtual bool slotInstallPackages() = 0;
Q_SLOT virtual bool slotUninstallPackage(int index) = 0;

virtual void reset() = 0;
virtual void resetInstallStatus() = 0;
Expand Down
58 changes: 31 additions & 27 deletions src/deb-installer/model/deblistmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,17 @@ const QString DebListModel::workerErrorString(const int errorCode, const QString
}
break;
// 无数字签名的错误
case DebListModel::NoDigitalSignature:
case Pkg::NoDigitalSignature:
return QApplication::translate("DebListModel", "No digital signature");

// 无有效的数字签名
case DebListModel::DigitalSignatureError:
case Pkg::DigitalSignatureError:
return QApplication::translate("DebListModel", "Invalid digital signature");

// 安装配置包时,没有得到授权
case DebListModel::ConfigAuthCancel:
case Pkg::ConfigAuthCancel:
return QApplication::translate("DebListModel", "Authentication failed");
case DebListModel::ErrorCode::ApplocationProhibit:
case Pkg::ApplocationProhibit:
return QApplication::translate("DebListModel",
"The administrator has set policies to prevent installation of this package");
default:
Expand Down Expand Up @@ -313,10 +313,10 @@ bool DebListModel::isDevelopMode()
return m_isDevelopMode;
}

void DebListModel::slotInstallPackages()
bool DebListModel::slotInstallPackages()
{
if (m_workerStatus != WorkerPrepare)
return;
return false;

m_workerStatus = WorkerProcessing; // 刷新包安装器的工作状态
m_operatingIndex = 0; // 初始化当前操作的index
Expand All @@ -329,11 +329,13 @@ void DebListModel::slotInstallPackages()
// 检查当前应用是否在黑名单中
// 非开发者模式且数字签名验证失败
if (checkBlackListApplication() || !checkDigitalSignature())
return;
return false;
installNextDeb(); // 开始安装

return true;
}

void DebListModel::slotUninstallPackage(int index)
bool DebListModel::slotUninstallPackage(int index)
{
m_workerStatus = WorkerProcessing; // 刷新当前包安装器的工作状态
m_operatingIndex = index; // 获取卸载的包的indx
Expand All @@ -343,7 +345,7 @@ void DebListModel::slotUninstallPackage(int index)

DebFile debFile(m_packagesManager->package(m_operatingIndex)); // 获取到包
if (!debFile.isValid())
return;
return false;
const QStringList rdepends =
m_packagesManager->packageReverseDependsList(debFile.packageName(), debFile.architecture()); // 检查是否有应用依赖到该包
qInfo() << QString("Will remove reverse depends before remove %1 , Lists:").arg(debFile.packageName()) << rdepends;
Expand All @@ -363,7 +365,7 @@ void DebListModel::slotUninstallPackage(int index)
// 未通过当前包的包名以及架构名称获取package对象,刷新操作状态为卸载失败
if (!uninstalledPackage) {
refreshOperatingPackageStatus(Pkg::PackageOperationStatus::Failed);
return;
return false;
}
uninstalledPackage->setPurge();

Expand Down Expand Up @@ -391,6 +393,8 @@ void DebListModel::slotUninstallPackage(int index)
m_currentTransaction = transsaction; // 保存trans指针

transsaction->run(); // 开始卸载

return true;
}

void DebListModel::removePackage(const int idx)
Expand All @@ -407,14 +411,14 @@ void DebListModel::removePackage(const int idx)
m_packagesManager->removePackage(idx); // 在packageManager中删除标记的下标
}

int DebListModel::checkInstallStatus(const QString &package_path)
Pkg::PackageInstallStatus DebListModel::checkInstallStatus(const QString &package_path)
{
return m_packagesManager->checkInstallStatus(package_path);
}

int DebListModel::checkDependsStatus(const QString &package_path)
Pkg::DependsStatus DebListModel::checkDependsStatus(const QString &package_path)
{
return m_packagesManager->checkDependsStatus(package_path).status;
return static_cast<Pkg::DependsStatus>(m_packagesManager->checkDependsStatus(package_path).status);
}

int DebListModel::checkDigitalSignature(const QString &package_path)
Expand Down Expand Up @@ -444,11 +448,11 @@ QStringList DebListModel::getPackageInfo(const QString &package_path)
return m_packagesManager->getPackageInfo(package_path);
}

QString DebListModel::getInstallErrorMessage()
QString DebListModel::lastProcessError()
{
if (m_currentTransaction)
return m_currentTransaction->errorString();
return "faild";
return "failed";
}

QString DebListModel::checkPackageValid(const QString &package_path)
Expand Down Expand Up @@ -673,7 +677,7 @@ void DebListModel::slotTransactionFinished()
// 保存错误原因和错误代码
// 修改map存储的数据格式,将错误原因与错误代码与包绑定,而非与下标绑定
m_packageFailCode[m_operatingPackageMd5] =
verifyError ? static_cast<int>(DebListModel::DigitalSignatureError) : static_cast<int>(transaction->error());
verifyError ? static_cast<int>(Pkg::DigitalSignatureError) : static_cast<int>(transaction->error());
m_packageFailReason[m_operatingPackageMd5] = transaction->errorString();

// 刷新操作状态
Expand Down Expand Up @@ -882,7 +886,7 @@ void DebListModel::installDebs()
m_currentTransaction->run();
}

void DebListModel::digitalVerifyFailed(ErrorCode errorCode)
void DebListModel::digitalVerifyFailed(Pkg::ErrorCode errorCode)
{
if (preparedPackages().size() > 1) { // 批量安装
refreshOperatingPackageStatus(Pkg::PackageOperationStatus::Failed); // 刷新操作状态
Expand Down Expand Up @@ -946,7 +950,7 @@ void DebListModel::showNoDigitalErrWindow()

// 批量安装时,如果不是最后一个包,则不弹窗,只记录详细错误原因。
if (m_operatingIndex < m_packagesManager->m_preparedPackages.size() - 1) {
digitalVerifyFailed(NoDigitalSignature); // 刷新安装错误,并记录错误原因
digitalVerifyFailed(Pkg::NoDigitalSignature); // 刷新安装错误,并记录错误原因
return;
}
DDialog *Ddialog = new DDialog(); // 弹出窗口
Expand Down Expand Up @@ -994,7 +998,7 @@ void DebListModel::showDigitalErrWindow(bool recordError)
// 批量安装时,如果不是最后一个包,则不弹窗,只记录详细错误原因。
if (m_operatingIndex < m_packagesManager->m_preparedPackages.size() - 1) {
if (recordError) {
digitalVerifyFailed(DigitalSignatureError); // 刷新安装错误,并记录错误原因
digitalVerifyFailed(Pkg::DigitalSignatureError); // 刷新安装错误,并记录错误原因
}
return;
}
Expand Down Expand Up @@ -1036,7 +1040,7 @@ void DebListModel::showDigitalErrWindow(bool recordError)
connect(Ddialog, &DDialog::rejected, exitOperate);
}

void DebListModel::showDevelopDigitalErrWindow(ErrorCode code)
void DebListModel::showDevelopDigitalErrWindow(Pkg::ErrorCode code)
{
Dialog *Ddialog = new Dialog();
// 设置窗口焦点
Expand Down Expand Up @@ -1081,12 +1085,12 @@ void DebListModel::showDevelopDigitalErrWindow(ErrorCode code)

void DebListModel::slotDigitalSignatureError()
{
digitalVerifyFailed(DigitalSignatureError);
digitalVerifyFailed(Pkg::DigitalSignatureError);
}

void DebListModel::slotNoDigitalSignature()
{
digitalVerifyFailed(NoDigitalSignature);
digitalVerifyFailed(Pkg::NoDigitalSignature);
}

void DebListModel::slotShowDevelopModeWindow()
Expand Down Expand Up @@ -1163,11 +1167,11 @@ bool DebListModel::checkDigitalSignature()
if (digitalSigntual == Utils::VerifySuccess) {
return true;
} else {
ErrorCode code;
Pkg::ErrorCode code;
if (digitalSigntual == Utils::DebfileInexistence)
code = NoDigitalSignature;
code = Pkg::NoDigitalSignature;
else
code = DigitalSignatureError;
code = Pkg::DigitalSignatureError;
showDevelopDigitalErrWindow(code); // 弹出提示框
return false;
}
Expand Down Expand Up @@ -1508,13 +1512,13 @@ void DebListModel::getPackageMd5(const QList<QByteArray> &packagesMD5)

void DebListModel::slotShowProhibitWindow()
{
digitalVerifyFailed(ApplocationProhibit);
digitalVerifyFailed(Pkg::ApplocationProhibit);
}
void DebListModel::showProhibitWindow()
{
// 批量安装时,如果不是最后一个包,则不弹窗,只记录详细错误原因。
if (m_operatingIndex < m_packagesManager->m_preparedPackages.size() - 1) {
digitalVerifyFailed(ApplocationProhibit); // 刷新安装错误,并记录错误原因
digitalVerifyFailed(Pkg::ApplocationProhibit); // 刷新安装错误,并记录错误原因
return;
}
DDialog *Ddialog = new DDialog();
Expand Down
21 changes: 10 additions & 11 deletions src/deb-installer/model/deblistmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,12 @@ class DebListModel : public AbstractPackageListModel
* @brief checkPackageDigitalSignature 查找指定包安装状态
* @param package_path 路径
*/
int checkInstallStatus(const QString &package_path);
Pkg::PackageInstallStatus checkInstallStatus(const QString &package_path) override;
/**
* @brief searchPackageInstallInfo 查找指定包依赖
* @param package_path 路径
*/
int checkDependsStatus(const QString &package_path);
Pkg::DependsStatus checkDependsStatus(const QString &package_path) override;
/**
* @brief searchPackageInstallInfo 查找指定包数字签名
* @param package_path 路径
Expand All @@ -164,11 +164,10 @@ class DebListModel : public AbstractPackageListModel
* @brief searchPackageInstallInfo 查找指定包信息
* @param package_path 路径
*/
QStringList getPackageInfo(const QString &package_path);
/**
* @brief getInstallErrorMessage 安装错误信息
*/
QString getInstallErrorMessage();
QStringList getPackageInfo(const QString &package_path) override;

QString lastProcessError() override;

/**
* @brief checkPackageValid 查找指定包信息
* @param package_path 路径
Expand Down Expand Up @@ -201,13 +200,13 @@ public slots:
/**
* @brief slotInstallPackages 开始安装所有的包
*/
void slotInstallPackages() override;
bool slotInstallPackages() override;

/**
* @brief slotUninstallPackage 卸载某一个包
* @param index 包的index
*/
void slotUninstallPackage(int index) override;
bool slotUninstallPackage(int index) override;

/**
* @brief slotAppendPackage 添加包
Expand Down Expand Up @@ -388,7 +387,7 @@ private slots:
/**
* @brief showDevelopDigitalErrWindow 开发者模式下弹出数字签名无效的弹窗
*/
void showDevelopDigitalErrWindow(ErrorCode code);
void showDevelopDigitalErrWindow(Pkg::ErrorCode code);

/**
* @brief showNoDigitalErrWindowInDdimProcess DDIM流程下的签名错误弹窗
Expand Down Expand Up @@ -418,7 +417,7 @@ private slots:
*
* @param errorCode 错误原因代码
*/
void digitalVerifyFailed(ErrorCode errorCode);
void digitalVerifyFailed(Pkg::ErrorCode errorCode);

private:
/**
Expand Down
Loading

0 comments on commit 50608f9

Please sign in to comment.