From 341d9dc809bd10fd0efaa269378345e1ce18955f Mon Sep 17 00:00:00 2001 From: trnsmkot Date: Mon, 6 Apr 2026 18:02:59 +0700 Subject: [PATCH] Add cross-platform archive creation for event and log exports using platform-specific tools (`zip` and PowerShell). --- views/event/EventWindow.cpp | 34 ++++++++++++++++++++++------------ views/log/FileLogWindow.cpp | 34 ++++++++++++++++++++++------------ 2 files changed, 44 insertions(+), 24 deletions(-) diff --git a/views/event/EventWindow.cpp b/views/event/EventWindow.cpp index ffe7f16..373537a 100644 --- a/views/event/EventWindow.cpp +++ b/views/event/EventWindow.cpp @@ -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("Отправить"); diff --git a/views/log/FileLogWindow.cpp b/views/log/FileLogWindow.cpp index bc0f62a..8a16b1c 100644 --- a/views/log/FileLogWindow.cpp +++ b/views/log/FileLogWindow.cpp @@ -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("Отправить");