From 88ddb97a52afeef05e298b011a5323064e33f57c Mon Sep 17 00:00:00 2001 From: Srivats P Date: Fri, 14 Feb 2020 18:47:02 +0530 Subject: [PATCH] Find Wireshark exe path when given .app path Also change the default Wireshark path value to match what recent versions of Wireshark are using Fixes #288 --- client/preferences.cpp | 26 ++++++++++++++++++++++++++ client/settings.h | 2 +- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/client/preferences.cpp b/client/preferences.cpp index 06a18b1..c516074 100644 --- a/client/preferences.cpp +++ b/client/preferences.cpp @@ -24,6 +24,7 @@ along with this program. If not, see #include #include +#include #if defined(Q_OS_WIN32) QString kGzipPathDefaultValue; @@ -98,6 +99,31 @@ void Preferences::on_wiresharkPathButton_clicked() path = QFileDialog::getOpenFileName(0, "Locate Wireshark", wiresharkPathEdit->text()); +#ifdef Q_OS_MAC + // Find executable inside app bundle using Info.plist + if (!path.isEmpty() && path.endsWith(".app")) { + QFile plist(path+"/Contents/Info.plist"); + plist.open(QIODevice::ReadOnly); + QXmlStreamReader xml(&plist); + + while (!xml.atEnd()) { + xml.readNext(); + if (xml.isStartElement() + && (xml.name() == "key") + && (xml.readElementText() == "CFBundleExecutable")) { + xml.readNext(); // + xml.readNext(); // + if (xml.isStartElement() && (xml.name() == "string")) + path = path+"/Contents/MacOs/"+xml.readElementText(); + break; + } + if (xml.hasError()) + qDebug("%lld:%lld Error reading Info.plist: %s", + xml.lineNumber(), xml.columnNumber(), + qPrintable(xml.errorString())); + } + } +#endif if (!path.isEmpty()) wiresharkPathEdit->setText(path); diff --git a/client/settings.h b/client/settings.h index bc4d069..fcf5743 100644 --- a/client/settings.h +++ b/client/settings.h @@ -31,7 +31,7 @@ const QString kWiresharkPathDefaultValue( "C:/Program Files/Wireshark/wireshark.exe"); #elif defined(Q_OS_MAC) const QString kWiresharkPathDefaultValue( - "/Applications/Wireshark.app/Contents/Resources/bin/wireshark"); + "/Applications/Wireshark.app/Contents/MacOS/Wireshark"); #else const QString kWiresharkPathDefaultValue("/usr/bin/wireshark"); #endif