mirror of
https://gitee.com/spark-store-project/spark-store
synced 2025-12-20 03:01:36 +08:00
update:保存日志到/tmp
This commit is contained in:
@@ -240,33 +240,72 @@ void AppDelegate::startNextInstall() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_installProcess = new QProcess(this);
|
m_installProcess = new QProcess(this);
|
||||||
connect(m_installProcess, &QProcess::readyReadStandardOutput, this, [this, packageName]() {
|
|
||||||
QByteArray out = m_installProcess->readAllStandardOutput();
|
// 新增:准备安装日志文件
|
||||||
QString text = QString::fromLocal8Bit(out);
|
QString logPath = QString("/tmp/%1_install.log").arg(packageName);
|
||||||
qDebug().noquote() << text;
|
QFile *logFile = new QFile(logPath, m_installProcess);
|
||||||
// 检查“软件包已安装”关键字
|
if (logFile->open(QIODevice::Append | QIODevice::Text)) {
|
||||||
if (text.contains(QStringLiteral("软件包已安装"))) {
|
// 设置权限为777
|
||||||
m_downloads[packageName].isInstalling = false;
|
QFile::setPermissions(logPath, QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner |
|
||||||
m_downloads[packageName].isInstalled = true;
|
QFile::ReadGroup | QFile::WriteGroup | QFile::ExeGroup |
|
||||||
|
QFile::ReadOther | QFile::WriteOther | QFile::ExeOther);
|
||||||
|
connect(m_installProcess, &QProcess::readyReadStandardOutput, this, [this, packageName, logFile]() {
|
||||||
|
QByteArray out = m_installProcess->readAllStandardOutput();
|
||||||
|
logFile->write(out);
|
||||||
|
logFile->flush();
|
||||||
|
QString text = QString::fromLocal8Bit(out);
|
||||||
|
qDebug().noquote() << text;
|
||||||
|
// 检查“软件包已安装”关键字
|
||||||
|
if (text.contains(QStringLiteral("软件包已安装"))) {
|
||||||
|
m_downloads[packageName].isInstalling = false;
|
||||||
|
m_downloads[packageName].isInstalled = true;
|
||||||
|
emit updateDisplay(packageName);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
connect(m_installProcess, &QProcess::readyReadStandardError, this, [this, logFile]() {
|
||||||
|
QByteArray err = m_installProcess->readAllStandardError();
|
||||||
|
logFile->write(err);
|
||||||
|
logFile->flush();
|
||||||
|
qDebug().noquote() << QString::fromLocal8Bit(err);
|
||||||
|
});
|
||||||
|
connect(m_installProcess, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
|
||||||
|
this, [this, packageName, logFile](int /*exitCode*/, QProcess::ExitStatus /*status*/) {
|
||||||
|
if (logFile) logFile->close();
|
||||||
|
// 若未检测到“软件包已安装”,此处兜底
|
||||||
|
if (!m_downloads[packageName].isInstalled) {
|
||||||
|
m_downloads[packageName].isInstalling = false;
|
||||||
|
}
|
||||||
emit updateDisplay(packageName);
|
emit updateDisplay(packageName);
|
||||||
}
|
m_installProcess->deleteLater();
|
||||||
});
|
m_installProcess = nullptr;
|
||||||
connect(m_installProcess, &QProcess::readyReadStandardError, this, [this]() {
|
m_installingPackage.clear();
|
||||||
QByteArray err = m_installProcess->readAllStandardError();
|
startNextInstall();
|
||||||
qDebug().noquote() << QString::fromLocal8Bit(err);
|
});
|
||||||
});
|
} else {
|
||||||
connect(m_installProcess, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
|
// 日志文件无法打开时,仍然要连接原有信号
|
||||||
this, [this, packageName](int /*exitCode*/, QProcess::ExitStatus /*status*/) {
|
connect(m_installProcess, &QProcess::readyReadStandardOutput, this, [this, packageName]() {
|
||||||
// 若未检测到“软件包已安装”,此处兜底
|
QByteArray out = m_installProcess->readAllStandardOutput();
|
||||||
if (!m_downloads[packageName].isInstalled) {
|
QString text = QString::fromLocal8Bit(out);
|
||||||
m_downloads[packageName].isInstalling = false;
|
qDebug().noquote() << text;
|
||||||
}
|
if (text.contains(QStringLiteral("软件包已安装"))) {
|
||||||
emit updateDisplay(packageName);
|
m_downloads[packageName].isInstalling = false;
|
||||||
m_installProcess->deleteLater();
|
m_downloads[packageName].isInstalled = true;
|
||||||
m_installProcess = nullptr;
|
emit updateDisplay(packageName);
|
||||||
m_installingPackage.clear();
|
}
|
||||||
startNextInstall();
|
});
|
||||||
});
|
connect(m_installProcess, &QProcess::readyReadStandardError, this, [this]() {
|
||||||
|
QByteArray err = m_installProcess->readAllStandardError();
|
||||||
|
qDebug().noquote() << QString::fromLocal8Bit(err);
|
||||||
|
});
|
||||||
|
connect(m_installProcess, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
|
||||||
|
this, [this, packageName](int /*exitCode*/, QProcess::ExitStatus /*status*/) {
|
||||||
|
emit updateDisplay(packageName);
|
||||||
|
m_installProcess->deleteLater();
|
||||||
|
m_installProcess = nullptr;
|
||||||
|
m_installingPackage.clear();
|
||||||
|
startNextInstall();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// 注意参数顺序:deb路径在前,--no-create-desktop-entry在后
|
// 注意参数顺序:deb路径在前,--no-create-desktop-entry在后
|
||||||
QStringList args;
|
QStringList args;
|
||||||
|
|||||||
@@ -33,20 +33,37 @@ void DownloadManager::startDownload(const QString &packageName, const QString &u
|
|||||||
QProcess *process = new QProcess(this);
|
QProcess *process = new QProcess(this);
|
||||||
m_processes.insert(packageName, process);
|
m_processes.insert(packageName, process);
|
||||||
|
|
||||||
connect(process, &QProcess::readyReadStandardOutput, this, [this, packageName, process]() {
|
// 新增:准备日志文件
|
||||||
while (process->canReadLine()) {
|
QString logPath = QString("/tmp/%1_download.log").arg(packageName);
|
||||||
QString line = QString::fromUtf8(process->readLine()).trimmed();
|
QFile *logFile = new QFile(logPath, process);
|
||||||
QRegularExpression regex(R"(\((\d+)%\))");
|
if (logFile->open(QIODevice::Append | QIODevice::Text)) {
|
||||||
QRegularExpressionMatch match = regex.match(line);
|
// 设置权限为777
|
||||||
if (match.hasMatch()) {
|
QFile::setPermissions(logPath, QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner |
|
||||||
int progress = match.captured(1).toInt();
|
QFile::ReadGroup | QFile::WriteGroup | QFile::ExeGroup |
|
||||||
emit downloadProgress(packageName, progress);
|
QFile::ReadOther | QFile::WriteOther | QFile::ExeOther);
|
||||||
|
connect(process, &QProcess::readyReadStandardOutput, this, [this, packageName, process, logFile]() {
|
||||||
|
while (process->canReadLine()) {
|
||||||
|
QString line = QString::fromUtf8(process->readLine()).trimmed();
|
||||||
|
// 写入日志
|
||||||
|
logFile->write(line.toUtf8() + '\n');
|
||||||
|
logFile->flush();
|
||||||
|
QRegularExpression regex(R"(\((\d+)%\))");
|
||||||
|
QRegularExpressionMatch match = regex.match(line);
|
||||||
|
if (match.hasMatch()) {
|
||||||
|
int progress = match.captured(1).toInt();
|
||||||
|
emit downloadProgress(packageName, progress);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
connect(process, &QProcess::readyReadStandardError, this, [process, logFile]() {
|
||||||
|
QByteArray err = process->readAllStandardError();
|
||||||
|
logFile->write(err);
|
||||||
|
logFile->flush();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
connect(process, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
|
connect(process, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
|
||||||
this, [this, packageName, outputPath](int exitCode, QProcess::ExitStatus status) {
|
this, [this, packageName, outputPath, logFile](int exitCode, QProcess::ExitStatus status) {
|
||||||
bool success = (exitCode == 0 && status == QProcess::NormalExit);
|
bool success = (exitCode == 0 && status == QProcess::NormalExit);
|
||||||
if (!success) {
|
if (!success) {
|
||||||
qWarning() << "Download failed for" << packageName << "exit code:" << exitCode;
|
qWarning() << "Download failed for" << packageName << "exit code:" << exitCode;
|
||||||
@@ -55,6 +72,8 @@ void DownloadManager::startDownload(const QString &packageName, const QString &u
|
|||||||
removeAria2Files(outputPath); // 清理残留 .aria2
|
removeAria2Files(outputPath); // 清理残留 .aria2
|
||||||
emit downloadFinished(packageName, success);
|
emit downloadFinished(packageName, success);
|
||||||
|
|
||||||
|
if (logFile) logFile->close();
|
||||||
|
|
||||||
QProcess *proc = m_processes.take(packageName);
|
QProcess *proc = m_processes.take(packageName);
|
||||||
if (proc) proc->deleteLater();
|
if (proc) proc->deleteLater();
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user