From b157f134d4ca45a43ac047ff510769b97147071e Mon Sep 17 00:00:00 2001 From: momen Date: Mon, 13 Oct 2025 16:58:00 +0800 Subject: [PATCH] =?UTF-8?q?chore:=E6=9B=B4=E6=96=B0=E8=BD=AF=E4=BB=B6?= =?UTF-8?q?=E5=90=8E=EF=BC=8C=E5=88=A0=E9=99=A4deb=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/appdelegate.cpp | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/src/appdelegate.cpp b/src/appdelegate.cpp index c9e4540..c9f851e 100644 --- a/src/appdelegate.cpp +++ b/src/appdelegate.cpp @@ -369,11 +369,20 @@ void AppDelegate::startNextInstall() { qDebug().noquote() << QString::fromLocal8Bit(err); }); connect(m_installProcess, QOverload::of(&QProcess::finished), - this, [this, packageName, logFile](int exitCode, QProcess::ExitStatus status) { + this, [this, packageName, logFile, debPath](int exitCode, QProcess::ExitStatus status) { if (logFile) logFile->close(); m_downloads[packageName].isInstalling = false; if (exitCode == 0) { m_downloads[packageName].isInstalled = true; + + // 安装成功后删除deb包 + if (QFile::exists(debPath)) { + if (QFile::remove(debPath)) { + qDebug() << "已删除deb包:" << debPath; + } else { + qWarning() << "删除deb包失败:" << debPath; + } + } } emit updateDisplay(packageName); m_installProcess->deleteLater(); @@ -382,13 +391,23 @@ void AppDelegate::startNextInstall() { startNextInstall(); }); } else { - connect(m_installProcess, &QProcess::readyReadStandardOutput, this, [this, packageName]() { + connect(m_installProcess, &QProcess::readyReadStandardOutput, this, [this, packageName, debPath]() { QByteArray out = m_installProcess->readAllStandardOutput(); QString text = QString::fromLocal8Bit(out); qDebug().noquote() << text; if (text.contains(QStringLiteral("软件包已安装"))) { m_downloads[packageName].isInstalling = false; m_downloads[packageName].isInstalled = true; + + // 安装成功后删除deb包 + if (QFile::exists(debPath)) { + if (QFile::remove(debPath)) { + qDebug() << "已删除deb包:" << debPath; + } else { + qWarning() << "删除deb包失败:" << debPath; + } + } + emit updateDisplay(packageName); } }); @@ -397,7 +416,16 @@ void AppDelegate::startNextInstall() { qDebug().noquote() << QString::fromLocal8Bit(err); }); connect(m_installProcess, QOverload::of(&QProcess::finished), - this, [this, packageName](int /*exitCode*/, QProcess::ExitStatus /*status*/) { + this, [this, packageName, debPath](int exitCode, QProcess::ExitStatus /*status*/) { + // 如果通过退出码判断安装成功,也删除deb包 + if (exitCode == 0 && QFile::exists(debPath)) { + if (QFile::remove(debPath)) { + qDebug() << "已删除deb包:" << debPath; + } else { + qWarning() << "删除deb包失败:" << debPath; + } + } + emit updateDisplay(packageName); m_installProcess->deleteLater(); m_installProcess = nullptr;