diff --git a/desktop/main.cpp b/desktop/main.cpp index a570faad3a..8aad51eb8b 100644 --- a/desktop/main.cpp +++ b/desktop/main.cpp @@ -167,6 +167,19 @@ void exceptionPostHandledCallback() { #endif } +QString getDataStoragePath() { + QString dataStoragePath; +#ifdef BUILD_FOR_BUNDLE + dataStoragePath = + QStandardPaths::writableLocation(QStandardPaths::AppDataLocation); + QDir dir(dataStoragePath); + if (!dir.exists()) { + dir.mkpath("."); + } +#endif + return dataStoragePath; +} + int main(int argc, char **argv) { QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling); @@ -179,9 +192,9 @@ int main(int argc, char **argv) { appPath.append(CRASH_REPORT_EXECUTABLE_RELATIVE_PATH); #endif - ExceptionGlobalHandler exceptionHandler(appPath + QDir::separator() + - CRASH_REPORT_EXECUTABLE, - exceptionPostHandledCallback); + ExceptionGlobalHandler exceptionHandler( + appPath + QDir::separator() + CRASH_REPORT_EXECUTABLE, + exceptionPostHandledCallback, getDataStoragePath()); Q_INIT_RESOURCE(react_resources); @@ -243,16 +256,6 @@ int main(int argc, char **argv) { #ifdef BUILD_FOR_BUNDLE -QString getDataStoragePath() { - QString dataStoragePath = - QStandardPaths::writableLocation(QStandardPaths::AppDataLocation); - QDir dir(dataStoragePath); - if (!dir.exists()) { - dir.mkpath("."); - } - return dataStoragePath; -} - void writeLogsToFile() { QMutexLocker locker(&consoleOutputMutex); QFile logFile(getDataStoragePath() + "/StatusIm.log"); diff --git a/desktop/reportApp/main.cpp b/desktop/reportApp/main.cpp index 6ae852a0b3..d319079cd7 100644 --- a/desktop/reportApp/main.cpp +++ b/desktop/reportApp/main.cpp @@ -17,7 +17,11 @@ const int MAIN_WINDOW_WIDTH = 1024; const int MAIN_WINDOW_HEIGHT = 768; -const int INPUT_ARGUMENTS_COUNT = 5; +const int INPUT_ARGUMENTS_COUNT = 6; + +const int MINIDUMP_FILE_PATH_ARG_INDEX = 1; +const int CRASHED_EXECUTABLE_PATH_ARG_INDEX = 2; +const int LOGS_PATH_INDEX = 5; int main(int argc, char **argv) { @@ -30,7 +34,9 @@ int main(int argc, char **argv) { app.setApplicationName("Crash Report"); - ReportPublisher reportPublisher(argv[1], argv[2]); + ReportPublisher reportPublisher(argv[MINIDUMP_FILE_PATH_ARG_INDEX], + argv[CRASHED_EXECUTABLE_PATH_ARG_INDEX], + argv[LOGS_PATH_INDEX]); QQuickView view; view.rootContext()->setContextProperty("reportPublisher", &reportPublisher); diff --git a/desktop/reportApp/reportpublisher.cpp b/desktop/reportApp/reportpublisher.cpp index c79d1fcdc3..4e1d266d2b 100644 --- a/desktop/reportApp/reportpublisher.cpp +++ b/desktop/reportApp/reportpublisher.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -22,9 +23,10 @@ const QString REPORT_SUBMIT_URL = QStringLiteral("https://goo.gl/forms/0705ZN0EMW3xLDpI2"); ReportPublisher::ReportPublisher(QString minidumpFilePath, - QString crashedExecutablePath, QObject *parent) + QString crashedExecutablePath, + QString logsPath, QObject *parent) : QObject(parent), m_minidumpFilePath(minidumpFilePath), - m_crashedExecutablePath(crashedExecutablePath) {} + m_logsPath(logsPath), m_crashedExecutablePath(crashedExecutablePath) {} void ReportPublisher::submit() { QDesktopServices::openUrl(QUrl(REPORT_SUBMIT_URL)); @@ -73,7 +75,21 @@ bool ReportPublisher::prepareReportFiles(QString reportDirPath) { reportDirPath + QDir::separator() + "crash.dmp") && QFile::copy(m_crashedExecutablePath, reportDirPath + QDir::separator() + - crashedExecutableFileInfo.fileName()); + 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; } QString ReportPublisher::resolveDataStoragePath() { diff --git a/desktop/reportApp/reportpublisher.h b/desktop/reportApp/reportpublisher.h index dc411a5c90..695dbd3445 100644 --- a/desktop/reportApp/reportpublisher.h +++ b/desktop/reportApp/reportpublisher.h @@ -15,25 +15,26 @@ #include class ReportPublisher : public QObject { - Q_OBJECT + Q_OBJECT public: - ReportPublisher(QString minidumpFilePath, QString crashedExecutablePath, QObject* parent = 0); + ReportPublisher(QString minidumpFilePath, QString crashedExecutablePath, + QString logsPath, QObject *parent = 0); - Q_INVOKABLE void submit(); - Q_INVOKABLE void restartAndQuit(); - Q_INVOKABLE void quit(); - Q_INVOKABLE void showDirectory(); - Q_INVOKABLE QString resolveDataStoragePath(); + Q_INVOKABLE void submit(); + Q_INVOKABLE void restartAndQuit(); + Q_INVOKABLE void quit(); + Q_INVOKABLE void showDirectory(); + Q_INVOKABLE QString resolveDataStoragePath(); private: + bool prepareReportFiles(QString reportDirPath); + bool prepareLogFiles(QString reportDirPath); - bool prepareReportFiles(QString reportDirPath); - - QString m_minidumpFilePath; - QString m_crashedExecutablePath; - bool m_logFilesPrepared = false; + QString m_minidumpFilePath; + QString m_crashedExecutablePath; + QString m_logsPath; + bool m_logFilesPrepared = false; }; - #endif // REPORTPUBLISHER