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:
slava 2026-04-06 18:02:59 +07:00
parent 6647a91c88
commit b2bbb2207f
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"; #ifdef Q_OS_WIN
QFile::remove(zipPath); const QString archivePath = QDir::tempPath() + "/arc_events.zip";
QFile::remove(archivePath);
QProcess zip; QProcess archiver;
zip.setWorkingDirectory(tmpDir); archiver.setWorkingDirectory(tmpDir);
zip.start("zip", QStringList() << "-r" << zipPath << "."); archiver.start("powershell", QStringList()
zip.waitForFinished(30000); << "-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(); QDir(tmpDir).removeRecursively();
if (zip.exitCode() != 0 || !QFile::exists(zipPath)) { if (!QFile::exists(archivePath)) {
QMessageBox::warning(this, "Ошибка", "Не удалось создать архив"); QMessageBox::warning(this, "Ошибка", "Не удалось создать архив");
m_sendBtn->setEnabled(true); m_sendBtn->setEnabled(true);
m_sendBtn->setText("Отправить"); m_sendBtn->setText("Отправить");
@ -349,7 +359,7 @@ void EventWindow::sendEventsToCsv() {
+ "\nTotal: " + QString::number(events.size()) + "\nTotal: " + QString::number(events.size())
+ "\nScreenshots: " + QString::number(screenshotCount); + "\nScreenshots: " + QString::number(screenshotCount);
auto *sendFile = new QFile(zipPath); auto *sendFile = new QFile(archivePath);
if (!sendFile->open(QIODevice::ReadOnly)) { if (!sendFile->open(QIODevice::ReadOnly)) {
QMessageBox::warning(this, "Ошибка", "Не удалось открыть архив"); QMessageBox::warning(this, "Ошибка", "Не удалось открыть архив");
delete sendFile; delete sendFile;
@ -383,10 +393,10 @@ void EventWindow::sendEventsToCsv() {
QNetworkReply *reply = manager->post(QNetworkRequest(url), multiPart); QNetworkReply *reply = manager->post(QNetworkRequest(url), multiPart);
multiPart->setParent(reply); multiPart->setParent(reply);
connect(reply, &QNetworkReply::finished, this, [this, reply, manager, zipPath]() { connect(reply, &QNetworkReply::finished, this, [this, reply, manager, archivePath]() {
reply->deleteLater(); reply->deleteLater();
manager->deleteLater(); manager->deleteLater();
QFile::remove(zipPath); QFile::remove(archivePath);
m_sendBtn->setEnabled(true); m_sendBtn->setEnabled(true);
m_sendBtn->setText("Отправить"); m_sendBtn->setText("Отправить");

View File

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