1
0
forked from BRT/arc

Add cross-platform archive creation for event and log exports using platform-specific tools (zip and PowerShell).

This commit is contained in:
trnsmkot 2026-04-06 18:02:59 +07:00
parent 8d84ce7a47
commit 341d9dc809
2 changed files with 44 additions and 24 deletions

View File

@ -323,18 +323,28 @@ void EventWindow::sendEventsToCsv() {
}
}
// Создаём ZIP
const QString zipPath = QDir::tempPath() + "/arc_events.zip";
QFile::remove(zipPath);
QProcess zip;
zip.setWorkingDirectory(tmpDir);
zip.start("zip", QStringList() << "-r" << zipPath << ".");
zip.waitForFinished(30000);
// Создаём архив
#ifdef Q_OS_WIN
const QString archivePath = QDir::tempPath() + "/arc_events.zip";
QFile::remove(archivePath);
QProcess archiver;
archiver.setWorkingDirectory(tmpDir);
archiver.start("powershell", QStringList()
<< "-NoProfile" << "-Command"
<< QString("Compress-Archive -Path '%1/*' -DestinationPath '%2' -Force").arg(tmpDir, archivePath));
archiver.waitForFinished(30000);
#else
const QString archivePath = QDir::tempPath() + "/arc_events.zip";
QFile::remove(archivePath);
QProcess archiver;
archiver.setWorkingDirectory(tmpDir);
archiver.start("zip", QStringList() << "-r" << archivePath << ".");
archiver.waitForFinished(30000);
#endif
QDir(tmpDir).removeRecursively();
if (zip.exitCode() != 0 || !QFile::exists(zipPath)) {
if (!QFile::exists(archivePath)) {
QMessageBox::warning(this, "Ошибка", "Не удалось создать архив");
m_sendBtn->setEnabled(true);
m_sendBtn->setText("Отправить");
@ -349,7 +359,7 @@ void EventWindow::sendEventsToCsv() {
+ "\nTotal: " + QString::number(events.size())
+ "\nScreenshots: " + QString::number(screenshotCount);
auto *sendFile = new QFile(zipPath);
auto *sendFile = new QFile(archivePath);
if (!sendFile->open(QIODevice::ReadOnly)) {
QMessageBox::warning(this, "Ошибка", "Не удалось открыть архив");
delete sendFile;
@ -383,10 +393,10 @@ void EventWindow::sendEventsToCsv() {
QNetworkReply *reply = manager->post(QNetworkRequest(url), multiPart);
multiPart->setParent(reply);
connect(reply, &QNetworkReply::finished, this, [this, reply, manager, zipPath]() {
connect(reply, &QNetworkReply::finished, this, [this, reply, manager, archivePath]() {
reply->deleteLater();
manager->deleteLater();
QFile::remove(zipPath);
QFile::remove(archivePath);
m_sendBtn->setEnabled(true);
m_sendBtn->setText("Отправить");

View File

@ -234,19 +234,29 @@ void FileLogWindow::sendLogToTelegram() {
}
}
// 4. Создаём ZIP
const QString zipPath = QDir::tempPath() + "/arc_logs.zip";
QFile::remove(zipPath);
QProcess zip;
zip.setWorkingDirectory(tmpDir);
zip.start("zip", QStringList() << "-r" << zipPath << ".");
zip.waitForFinished(30000);
// 4. Создаём архив
#ifdef Q_OS_WIN
const QString archivePath = QDir::tempPath() + "/arc_logs.zip";
QFile::remove(archivePath);
QProcess archiver;
archiver.setWorkingDirectory(tmpDir);
archiver.start("powershell", QStringList()
<< "-NoProfile" << "-Command"
<< QString("Compress-Archive -Path '%1/*' -DestinationPath '%2' -Force").arg(tmpDir, archivePath));
archiver.waitForFinished(30000);
#else
const QString archivePath = QDir::tempPath() + "/arc_logs.zip";
QFile::remove(archivePath);
QProcess archiver;
archiver.setWorkingDirectory(tmpDir);
archiver.start("zip", QStringList() << "-r" << archivePath << ".");
archiver.waitForFinished(30000);
#endif
// Чистим временную папку
QDir(tmpDir).removeRecursively();
if (zip.exitCode() != 0 || !QFile::exists(zipPath)) {
if (!QFile::exists(archivePath)) {
QMessageBox::warning(this, "Ошибка", "Не удалось создать архив");
m_sendBtn->setEnabled(true);
m_sendBtn->setText("Отправить");
@ -255,7 +265,7 @@ void FileLogWindow::sendLogToTelegram() {
m_sendBtn->setText("Отправка...");
QFile *zipFile = new QFile(zipPath);
QFile *zipFile = new QFile(archivePath);
if (!zipFile->open(QIODevice::ReadOnly)) {
QMessageBox::warning(this, "Ошибка", "Не удалось открыть архив");
delete zipFile;
@ -298,10 +308,10 @@ void FileLogWindow::sendLogToTelegram() {
QNetworkReply *reply = manager->post(QNetworkRequest(url), multiPart);
multiPart->setParent(reply);
connect(reply, &QNetworkReply::finished, this, [this, reply, manager, zipPath]() {
connect(reply, &QNetworkReply::finished, this, [this, reply, manager, archivePath]() {
reply->deleteLater();
manager->deleteLater();
QFile::remove(zipPath);
QFile::remove(archivePath);
m_sendBtn->setEnabled(true);
m_sendBtn->setText("Отправить");