From d6a00523a8416371d3cd80bcace5f364f57538b5 Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 6 Jun 2018 21:45:32 +0300 Subject: [PATCH] Add crash annotations for file dialog. --- .../platform/win/file_utilities_win.cpp | 29 +++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/Telegram/SourceFiles/platform/win/file_utilities_win.cpp b/Telegram/SourceFiles/platform/win/file_utilities_win.cpp index c8fb4140a..f32fbca50 100644 --- a/Telegram/SourceFiles/platform/win/file_utilities_win.cpp +++ b/Telegram/SourceFiles/platform/win/file_utilities_win.cpp @@ -12,6 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "platform/win/windows_dlls.h" #include "lang/lang_keys.h" #include "messenger.h" +#include "core/crash_reports.h" #include #include @@ -371,43 +372,53 @@ bool Get( } dialog.show(); - auto realLastPath = ([startFile] { + auto realLastPath = [=] { // If we're given some non empty path containing a folder - use it. if (!startFile.isEmpty() && (startFile.indexOf('/') >= 0 || startFile.indexOf('\\') >= 0)) { return QFileInfo(startFile).dir().absolutePath(); } return cDialogLastPath(); - })(); + }(); if (realLastPath.isEmpty() || realLastPath.endsWith(qstr("/tdummy"))) { - realLastPath = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation); + realLastPath = QStandardPaths::writableLocation( + QStandardPaths::DownloadLocation); } dialog.setDirectory(realLastPath); + auto toSelect = startFile; if (type == Type::WriteFile) { - auto toSelect = startFile; - auto lastSlash = toSelect.lastIndexOf('/'); + const auto lastSlash = toSelect.lastIndexOf('/'); if (lastSlash >= 0) { toSelect = toSelect.mid(lastSlash + 1); } - auto lastBackSlash = toSelect.lastIndexOf('\\'); + const auto lastBackSlash = toSelect.lastIndexOf('\\'); if (lastBackSlash >= 0) { toSelect = toSelect.mid(lastBackSlash + 1); } dialog.selectFile(toSelect); } - int res = dialog.exec(); + CrashReports::SetAnnotation( + "file_dialog", + QString("caption:%1;helper:%2;filter:%3;real:%4;select:%5" + ).arg(caption + ).arg(helperPath + ).arg(filter + ).arg(realLastPath + ).arg(toSelect)); + const auto result = dialog.exec(); + CrashReports::ClearAnnotation("file_dialog"); if (type != Type::ReadFolder) { // Save last used directory for all queries except directory choosing. - auto path = dialog.directory().absolutePath(); + const auto path = dialog.directory().absolutePath(); if (path != cDialogLastPath()) { cSetDialogLastPath(path); Local::writeUserSettings(); } } - if (res == QDialog::Accepted) { + if (result == QDialog::Accepted) { if (type == Type::ReadFiles) { files = dialog.selectedFiles(); } else {