2018-08-29 22:45:19 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2017-present, Status Research and Development GmbH.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "reportpublisher.h"
|
|
|
|
|
|
|
|
#include <QApplication>
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QDesktopServices>
|
|
|
|
#include <QDir>
|
2018-09-06 16:51:49 +00:00
|
|
|
#include <QDirIterator>
|
2018-08-29 22:45:19 +00:00
|
|
|
#include <QFile>
|
|
|
|
#include <QProcess>
|
|
|
|
#include <QUrl>
|
|
|
|
|
|
|
|
const QString REPORT_SUBMIT_URL =
|
|
|
|
QStringLiteral("https://goo.gl/forms/0705ZN0EMW3xLDpI2");
|
|
|
|
|
|
|
|
ReportPublisher::ReportPublisher(QString minidumpFilePath,
|
2018-09-06 16:51:49 +00:00
|
|
|
QString crashedExecutablePath,
|
|
|
|
QString logsPath, QObject *parent)
|
2018-08-29 22:45:19 +00:00
|
|
|
: QObject(parent), m_minidumpFilePath(minidumpFilePath),
|
2018-09-06 16:51:49 +00:00
|
|
|
m_logsPath(logsPath), m_crashedExecutablePath(crashedExecutablePath) {}
|
2018-08-29 22:45:19 +00:00
|
|
|
|
|
|
|
void ReportPublisher::submit() {
|
|
|
|
QDesktopServices::openUrl(QUrl(REPORT_SUBMIT_URL));
|
|
|
|
showDirectory();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ReportPublisher::restartAndQuit() {
|
|
|
|
QString appPath = m_crashedExecutablePath;
|
|
|
|
|
|
|
|
#ifdef Q_OS_MACOS
|
|
|
|
QFileInfo crashedExecutableFileInfo(m_crashedExecutablePath);
|
|
|
|
QString fullPath = crashedExecutableFileInfo.dir().absolutePath();
|
|
|
|
const QString bundleExtension = QStringLiteral(".app");
|
|
|
|
if (fullPath.contains(bundleExtension)) {
|
|
|
|
appPath = fullPath.left(fullPath.indexOf(bundleExtension) +
|
|
|
|
bundleExtension.size());
|
|
|
|
}
|
|
|
|
QString cmd = QString("open %1").arg(appPath);
|
2018-09-26 14:40:41 +00:00
|
|
|
#else
|
2018-08-29 22:45:19 +00:00
|
|
|
QString cmd = appPath;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
QProcess::startDetached(cmd);
|
|
|
|
|
|
|
|
qApp->quit();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ReportPublisher::quit() { qApp->quit(); }
|
|
|
|
|
|
|
|
void ReportPublisher::showDirectory() {
|
|
|
|
QString dataStoragePath = resolveDataStoragePath();
|
|
|
|
if (!m_logFilesPrepared) {
|
|
|
|
m_logFilesPrepared = prepareReportFiles(dataStoragePath);
|
|
|
|
}
|
|
|
|
QDesktopServices::openUrl(
|
|
|
|
QUrl("file://" + dataStoragePath, QUrl::TolerantMode));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ReportPublisher::prepareReportFiles(QString reportDirPath) {
|
|
|
|
QFileInfo minidumpFileInfo(m_minidumpFilePath);
|
|
|
|
QFileInfo crashedExecutableFileInfo(m_crashedExecutablePath);
|
|
|
|
if (!minidumpFileInfo.exists() || !crashedExecutableFileInfo.exists())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return QFile::copy(m_minidumpFilePath,
|
|
|
|
reportDirPath + QDir::separator() + "crash.dmp") &&
|
|
|
|
QFile::copy(m_crashedExecutablePath,
|
|
|
|
reportDirPath + QDir::separator() +
|
2018-09-06 16:51:49 +00:00
|
|
|
crashedExecutableFileInfo.fileName()) &&
|
|
|
|
prepareLogFiles(reportDirPath);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ReportPublisher::prepareLogFiles(QString reportDirPath) {
|
|
|
|
if (reportDirPath.isEmpty())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
QDirIterator filesIterator(m_logsPath, QStringList() << "*.log", QDir::Files);
|
|
|
|
while (filesIterator.hasNext()) {
|
|
|
|
QFileInfo logFile(filesIterator.next());
|
|
|
|
QFile::copy(logFile.absoluteFilePath(),
|
|
|
|
reportDirPath + QDir::separator() + logFile.fileName());
|
|
|
|
}
|
|
|
|
return true;
|
2018-08-29 22:45:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QString ReportPublisher::resolveDataStoragePath() {
|
|
|
|
QFileInfo minidumpFileInfo(m_minidumpFilePath);
|
|
|
|
QString dataStoragePath =
|
2018-09-26 14:40:41 +00:00
|
|
|
QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) +
|
2018-08-29 22:45:19 +00:00
|
|
|
QDir::separator() + minidumpFileInfo.baseName();
|
|
|
|
QDir dir(dataStoragePath);
|
|
|
|
if (!dir.exists()) {
|
|
|
|
dir.mkpath(".");
|
|
|
|
}
|
|
|
|
return dataStoragePath;
|
|
|
|
}
|