Skip to content

Commit c3f171f

Browse files
committed
pcap: Add settings to Emu->Devtools
1 parent 40a0856 commit c3f171f

File tree

5 files changed

+115
-40
lines changed

5 files changed

+115
-40
lines changed

src/frontend/qt_sdl/Config.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,8 @@ LegacyEntry LegacyFile[] =
309309
{"GdbARM7BreakOnStartup", 1, "Gdb.ARM7.BreakOnStartup", true},
310310
{"GdbARM9BreakOnStartup", 1, "Gdb.ARM9.BreakOnStartup", true},
311311
#endif
312+
{"PcapEnabled", 1, "Pcap.Enabled", false},
313+
{"PcapPath", 2, "Pcap.Path", false},
312314

313315
{"Camera0_InputType", 0, "DSi.Camera0.InputType", false},
314316
{"Camera0_ImagePath", 2, "DSi.Camera0.ImagePath", false},

src/frontend/qt_sdl/EmuInstance.cpp

+7-4
Original file line numberDiff line numberDiff line change
@@ -2056,13 +2056,16 @@ void EmuInstance::animatedROMIcon(const u8 (&data)[8][512], const u16 (&palette)
20562056

20572057
void EmuInstance::startPacketCapture()
20582058
{
2059-
if (!pcap)
2060-
pcap = melonDS::LibPCap::New();
2061-
20622059
if (packetCapture != nullptr || packetCaptureDumper != nullptr)
20632060
stopPacketCapture();
20642061

2065-
std::string pcapPath = getAssetPath(false, globalCfg.GetString("PacketCapturePath"), instanceFileSuffix() + ".pcap");
2062+
if (!globalCfg.GetBool("Pcap.Enabled"))
2063+
return;
2064+
2065+
if (!pcap)
2066+
pcap = melonDS::LibPCap::New();
2067+
2068+
std::string pcapPath = getAssetPath(false, globalCfg.GetString("Pcap.Path"), instanceFileSuffix() + ".pcap");
20662069
Log(LogLevel::Debug, "Starting packet capture: %s\n", pcapPath.c_str());
20672070

20682071
packetCapture = pcap->open_dead(DLT_IEEE802_11, 1024);

src/frontend/qt_sdl/EmuSettingsDialog.cpp

+30
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include <QFileDialog>
2020
#include <QMessageBox>
21+
#include <QTemporaryFile>
2122

2223
#include "types.h"
2324
#include "Platform.h"
@@ -107,9 +108,12 @@ EmuSettingsDialog::EmuSettingsDialog(QWidget* parent) : QDialog(parent), ui(new
107108
ui->cbGdbBOSA7->setDisabled(true);
108109
ui->cbGdbBOSA9->setDisabled(true);
109110
#endif
111+
ui->cbPcapEnabled->setChecked(cfg.GetBool("Pcap.Enabled"));
112+
ui->txtPcapPath->setText(cfg.GetQString("Pcap.Path"));
110113

111114
on_chkEnableJIT_toggled();
112115
on_cbGdbEnabled_toggled();
116+
on_cbPcapEnabled_toggled();
113117
on_chkExternalBIOS_toggled();
114118

115119
const int imgsizes[] = {256, 512, 1024, 2048, 4096, 0};
@@ -292,6 +296,8 @@ void EmuSettingsDialog::done(int r)
292296
instcfg.SetBool("Gdb.ARM7.BreakOnStartup", ui->cbGdbBOSA7->isChecked());
293297
instcfg.SetBool("Gdb.ARM9.BreakOnStartup", ui->cbGdbBOSA9->isChecked());
294298
#endif
299+
cfg.SetBool("Pcap.Enabled", ui->cbPcapEnabled->isChecked());
300+
cfg.SetQString("Pcap.Path", ui->txtPcapPath->text());
295301

296302
cfg.SetInt("Emu.ConsoleType", ui->cbxConsoleType->currentIndex());
297303
cfg.SetBool("Emu.DirectBoot", ui->chkDirectBoot->isChecked());
@@ -565,6 +571,30 @@ void EmuSettingsDialog::on_cbGdbEnabled_toggled()
565571
ui->cbGdbBOSA9->setDisabled(disabled);
566572
}
567573

574+
void EmuSettingsDialog::on_cbPcapEnabled_toggled()
575+
{
576+
bool disabled = !ui->cbPcapEnabled->isChecked();
577+
ui->txtPcapPath->setDisabled(disabled);
578+
ui->btnPcapBrowse->setDisabled(disabled);
579+
}
580+
581+
void EmuSettingsDialog::on_btnPcapBrowse_clicked()
582+
{
583+
QString dir = QFileDialog::getExistingDirectory(this,
584+
"Select packet captures path...",
585+
lastBIOSFolder);
586+
587+
if (dir.isEmpty()) return;
588+
589+
if (!QTemporaryFile(dir).open())
590+
{
591+
QMessageBox::critical(this, "melonDS", "Unable to write to packet captures directory.\nPlease check file/folder write permissions.");
592+
return;
593+
}
594+
595+
ui->txtPcapPath->setText(dir);
596+
}
597+
568598
void EmuSettingsDialog::on_chkExternalBIOS_toggled()
569599
{
570600
bool disabled = !ui->chkExternalBIOS->isChecked();

src/frontend/qt_sdl/EmuSettingsDialog.h

+2
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ private slots:
8080
void on_chkExternalBIOS_toggled();
8181

8282
void on_cbGdbEnabled_toggled();
83+
void on_cbPcapEnabled_toggled();
84+
void on_btnPcapBrowse_clicked();
8385

8486
private:
8587
void verifyFirmware();

src/frontend/qt_sdl/EmuSettingsDialog.ui

+74-36
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<x>0</x>
88
<y>0</y>
99
<width>575</width>
10-
<height>416</height>
10+
<height>456</height>
1111
</rect>
1212
</property>
1313
<property name="sizePolicy">
@@ -21,7 +21,7 @@
2121
</property>
2222
<layout class="QVBoxLayout" name="verticalLayout">
2323
<property name="sizeConstraint">
24-
<enum>QLayout::SetFixedSize</enum>
24+
<enum>QLayout::SizeConstraint::SetFixedSize</enum>
2525
</property>
2626
<item>
2727
<widget class="QTabWidget" name="tabWidget">
@@ -59,7 +59,7 @@
5959
<item row="3" column="0">
6060
<spacer name="verticalSpacer_2">
6161
<property name="orientation">
62-
<enum>Qt::Vertical</enum>
62+
<enum>Qt::Orientation::Vertical</enum>
6363
</property>
6464
<property name="sizeHint" stdset="0">
6565
<size>
@@ -99,7 +99,7 @@
9999
<item row="4" column="0">
100100
<spacer name="verticalSpacer_5">
101101
<property name="orientation">
102-
<enum>Qt::Vertical</enum>
102+
<enum>Qt::Orientation::Vertical</enum>
103103
</property>
104104
<property name="sizeHint" stdset="0">
105105
<size>
@@ -457,7 +457,7 @@
457457
<item row="5" column="0">
458458
<spacer name="verticalSpacer">
459459
<property name="orientation">
460-
<enum>Qt::Vertical</enum>
460+
<enum>Qt::Orientation::Vertical</enum>
461461
</property>
462462
<property name="sizeHint" stdset="0">
463463
<size>
@@ -539,7 +539,7 @@
539539
<item row="5" column="0">
540540
<spacer name="verticalSpacer_3">
541541
<property name="orientation">
542-
<enum>Qt::Vertical</enum>
542+
<enum>Qt::Orientation::Vertical</enum>
543543
</property>
544544
<property name="sizeHint" stdset="0">
545545
<size>
@@ -573,17 +573,38 @@
573573
<string>Devtools</string>
574574
</attribute>
575575
<layout class="QGridLayout" name="gridLayout_3">
576-
<item row="1" column="0">
577-
<widget class="QLabel" name="label_16">
576+
<item row="2" column="0">
577+
<widget class="QLabel" name="label_17">
578578
<property name="text">
579-
<string>ARM9 port</string>
579+
<string>ARM7 port</string>
580580
</property>
581581
</widget>
582582
</item>
583-
<item row="5" column="0">
583+
<item row="2" column="5">
584+
<widget class="QCheckBox" name="cbGdbBOSA7">
585+
<property name="text">
586+
<string>Break on startup</string>
587+
</property>
588+
</widget>
589+
</item>
590+
<item row="9" column="0" colspan="6">
591+
<widget class="QLabel" name="label_23">
592+
<property name="text">
593+
<string>Packet captures are stored in .pcap format, by default in the same directory as the ROM.</string>
594+
</property>
595+
</widget>
596+
</item>
597+
<item row="7" column="5">
598+
<widget class="QPushButton" name="btnPcapBrowse">
599+
<property name="text">
600+
<string>Browse...</string>
601+
</property>
602+
</widget>
603+
</item>
604+
<item row="11" column="0">
584605
<spacer name="verticalSpacer_4">
585606
<property name="orientation">
586-
<enum>Qt::Vertical</enum>
607+
<enum>Qt::Orientation::Vertical</enum>
587608
</property>
588609
<property name="sizeHint" stdset="0">
589610
<size>
@@ -593,10 +614,10 @@
593614
</property>
594615
</spacer>
595616
</item>
596-
<item row="2" column="0">
597-
<widget class="QLabel" name="label_17">
617+
<item row="1" column="5">
618+
<widget class="QCheckBox" name="cbGdbBOSA9">
598619
<property name="text">
599-
<string>ARM7 port</string>
620+
<string>Break on startup</string>
600621
</property>
601622
</widget>
602623
</item>
@@ -607,28 +628,14 @@
607628
</property>
608629
</widget>
609630
</item>
610-
<item row="4" column="0" colspan="7">
631+
<item row="4" column="0" colspan="6">
611632
<widget class="QLabel" name="label_18">
612633
<property name="text">
613634
<string>Note: melonDS must be restarted in order for these changes to have effect</string>
614635
</property>
615636
</widget>
616637
</item>
617-
<item row="3" column="0" colspan="7">
618-
<widget class="QLabel" name="label_19">
619-
<property name="text">
620-
<string>Note: GDB stub cannot be used together with the JIT recompiler</string>
621-
</property>
622-
</widget>
623-
</item>
624-
<item row="1" column="6">
625-
<widget class="QCheckBox" name="cbGdbBOSA9">
626-
<property name="text">
627-
<string>Break on startup</string>
628-
</property>
629-
</widget>
630-
</item>
631-
<item row="1" column="1" colspan="5">
638+
<item row="1" column="1" colspan="4">
632639
<widget class="QSpinBox" name="intGdbPortA9">
633640
<property name="minimum">
634641
<number>1000</number>
@@ -641,7 +648,21 @@
641648
</property>
642649
</widget>
643650
</item>
644-
<item row="2" column="1" colspan="5">
651+
<item row="1" column="0">
652+
<widget class="QLabel" name="label_16">
653+
<property name="text">
654+
<string>ARM9 port</string>
655+
</property>
656+
</widget>
657+
</item>
658+
<item row="5" column="0">
659+
<widget class="QLabel" name="label_22">
660+
<property name="text">
661+
<string/>
662+
</property>
663+
</widget>
664+
</item>
665+
<item row="2" column="1" colspan="4">
645666
<widget class="QSpinBox" name="intGdbPortA7">
646667
<property name="minimum">
647668
<number>1000</number>
@@ -654,10 +675,27 @@
654675
</property>
655676
</widget>
656677
</item>
657-
<item row="2" column="6">
658-
<widget class="QCheckBox" name="cbGdbBOSA7">
678+
<item row="3" column="0" colspan="6">
679+
<widget class="QLabel" name="label_19">
659680
<property name="text">
660-
<string>Break on startup</string>
681+
<string>Note: GDB stub cannot be used together with the JIT recompiler</string>
682+
</property>
683+
</widget>
684+
</item>
685+
<item row="7" column="1" colspan="4">
686+
<widget class="QPathInput" name="txtPcapPath"/>
687+
</item>
688+
<item row="7" column="0">
689+
<widget class="QLabel" name="label_21">
690+
<property name="text">
691+
<string>Directory:</string>
692+
</property>
693+
</widget>
694+
</item>
695+
<item row="6" column="0" colspan="6">
696+
<widget class="QCheckBox" name="cbPcapEnabled">
697+
<property name="text">
698+
<string>Enable network packet capture</string>
661699
</property>
662700
</widget>
663701
</item>
@@ -668,10 +706,10 @@
668706
<item>
669707
<widget class="QDialogButtonBox" name="buttonBox">
670708
<property name="orientation">
671-
<enum>Qt::Horizontal</enum>
709+
<enum>Qt::Orientation::Horizontal</enum>
672710
</property>
673711
<property name="standardButtons">
674-
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
712+
<set>QDialogButtonBox::StandardButton::Cancel|QDialogButtonBox::StandardButton::Ok</set>
675713
</property>
676714
</widget>
677715
</item>

0 commit comments

Comments
 (0)