DEV9: Switch Linux config dialog to wx

This commit is contained in:
TellowKrinkle 2021-05-06 19:54:17 -05:00 committed by tellowkrinkle
parent 005f8c7d1d
commit 85bc4f1027
5 changed files with 248 additions and 819 deletions

View File

@ -321,30 +321,6 @@ set(pcsx2SPU2Headers
SPU2/WavFile.h SPU2/WavFile.h
) )
if(NOT WIN32)
# DEV9 UI sources
compile_gresources( pcsx2DEV9UISources
pcsx2DEV9UIXML
TYPE EMBED_C
RESOURCES "DEV9/Linux/dev9.ui"
PREFIX "/net/pcsx2/dev9"
COMPRESS_ALL
STRIPBLANKS_ALL
)
# DEV9 UI headers
compile_gresources( pcsx2DEV9UIHeaders
pcsx2DEV9UIXML
TYPE EMBED_H
RESOURCES "DEV9/Linux/dev9.ui"
PREFIX "/net/pcsx2/dev9"
COMPRESS_ALL
STRIPBLANKS_ALL
)
endif()
# DEV9 sources # DEV9 sources
set(pcsx2DEV9Sources set(pcsx2DEV9Sources
DEV9/ATA/Commands/ATA_Command.cpp DEV9/ATA/Commands/ATA_Command.cpp
@ -376,7 +352,6 @@ set(pcsx2DEV9Sources
DEV9/flash.cpp DEV9/flash.cpp
DEV9/pcap_io.cpp DEV9/pcap_io.cpp
DEV9/net.cpp DEV9/net.cpp
${pcsx2DEV9UISources}
) )
# DEV9 headers # DEV9 headers
@ -404,7 +379,6 @@ set(pcsx2DEV9Headers
DEV9/pcap_io.h DEV9/pcap_io.h
DEV9/SimpleQueue.h DEV9/SimpleQueue.h
DEV9/smap.h DEV9/smap.h
${pcsx2DEV9UIHeaders}
) )
# USBNull # USBNull

View File

@ -1,5 +1,5 @@
/* PCSX2 - PS2 Emulator for PCs /* PCSX2 - PS2 Emulator for PCs
* Copyright (C) 2002-2020 PCSX2 Dev Team * Copyright (C) 2002-2021 PCSX2 Dev Team
* *
* PCSX2 is free software: you can redistribute it and/or modify it under the terms * PCSX2 is free software: you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Found- * of the GNU Lesser General Public License as published by the Free Software Found-
@ -16,19 +16,16 @@
#include "PrecompiledHeader.h" #include "PrecompiledHeader.h"
#include <stdio.h> #include <stdio.h>
#include <arpa/inet.h>
#include <gtk/gtk.h>
#include <unistd.h>
#include <sys/types.h>
#include <pwd.h>
#include <string.h>
#include <vector> #include <vector>
#include "fmt/format.h" #include <ghc/filesystem.h>
#include <string> #include <wx/wx.h>
#include "ghc/filesystem.h" #include <wx/collpane.h>
#include <wx/filepicker.h>
#include <wx/slider.h>
#include <wx/spinctrl.h>
#include <wx/gbsizer.h>
#include "DEV9/Config.h" #include "DEV9/Config.h"
#include "DEV9/DEV9.h" #include "DEV9/DEV9.h"
@ -36,308 +33,281 @@
#include "DEV9/pcap_io.h" #include "DEV9/pcap_io.h"
#include "DEV9/net.h" #include "DEV9/net.h"
#include "DEV9/PacketReader/IP/IP_Address.h" #include "DEV9/PacketReader/IP/IP_Address.h"
#include "Config.h"
#include "gui/AppCoreThread.h" #include "gui/AppCoreThread.h"
#include "DEV9/ATA/HddCreate.h" #include "DEV9/ATA/HddCreate.h"
using PacketReader::IP::IP_Address; using PacketReader::IP::IP_Address;
static GtkBuilder* builder = nullptr; class DEV9Dialog : public wxDialog
std::vector<AdapterEntry> adapters;
void IPControl_SetValue(GtkEntry* entryCtl, IP_Address value)
{ {
char addrBuff[INET_ADDRSTRLEN] = {0}; static void IPControl_SetValue(wxTextCtrl* ctl, IP_Address value)
inet_ntop(AF_INET, &value, addrBuff, INET_ADDRSTRLEN);
gtk_entry_set_text(entryCtl, addrBuff);
}
IP_Address IPControl_GetValue(GtkEntry* entryCtl)
{
IP_Address ret;
if (inet_pton(AF_INET, gtk_entry_get_text(entryCtl), &ret) == 1)
return ret;
Console.Error("Invalid IP address entered");
return {0};
}
void IPControl_Enable(GtkEntry* ipEntry, bool enabled, IP_Address value)
{
if (enabled)
{ {
gtk_widget_set_sensitive((GtkWidget*)ipEntry, true); ctl->SetValue(wxString::Format("%u.%u.%u.%u", value.bytes[0], value.bytes[1], value.bytes[2], value.bytes[3]));
IPControl_SetValue(ipEntry, value);
}
else
{
gtk_widget_set_sensitive((GtkWidget*)ipEntry, false);
IPControl_SetValue(ipEntry, {0});
}
}
void OnAutoMaskChanged(GtkToggleButton* togglebutton, gpointer usr_data)
{
IPControl_Enable((GtkEntry*)gtk_builder_get_object(builder, "IDC_IPADDRESS_SUBNET"), !gtk_toggle_button_get_active(togglebutton), config.Mask);
}
void OnAutoGatewayChanged(GtkToggleButton* togglebutton, gpointer usr_data)
{
IPControl_Enable((GtkEntry*)gtk_builder_get_object(builder, "IDC_IPADDRESS_GATEWAY"), !gtk_toggle_button_get_active(togglebutton), config.Gateway);
}
void OnAutoDNS1Changed(GtkToggleButton* togglebutton, gpointer usr_data)
{
IPControl_Enable((GtkEntry*)gtk_builder_get_object(builder, "IDC_IPADDRESS_DNS1"), !gtk_toggle_button_get_active(togglebutton), config.DNS1);
}
void OnAutoDNS2Changed(GtkToggleButton* togglebutton, gpointer usr_data)
{
IPControl_Enable((GtkEntry*)gtk_builder_get_object(builder, "IDC_IPADDRESS_DNS2"), !gtk_toggle_button_get_active(togglebutton), config.DNS2);
}
void OnInterceptChanged(GtkToggleButton* togglebutton, gpointer usr_data)
{
if (gtk_toggle_button_get_active(togglebutton))
{
gtk_widget_set_sensitive((GtkWidget*)gtk_builder_get_object(builder, "IDC_IPADDRESS_IP"), true);
IPControl_SetValue((GtkEntry*)gtk_builder_get_object(builder, "IDC_IPADDRESS_IP"), config.PS2IP);
gtk_widget_set_sensitive((GtkWidget*)gtk_builder_get_object(builder, "IDC_CHECK_SUBNET"), true);
gtk_widget_set_sensitive((GtkWidget*)gtk_builder_get_object(builder, "IDC_CHECK_GATEWAY"), true);
gtk_widget_set_sensitive((GtkWidget*)gtk_builder_get_object(builder, "IDC_CHECK_DNS1"), true);
gtk_widget_set_sensitive((GtkWidget*)gtk_builder_get_object(builder, "IDC_CHECK_DNS2"), true);
gtk_toggle_button_set_active((GtkToggleButton*)gtk_builder_get_object(builder, "IDC_CHECK_SUBNET"), config.AutoMask);
gtk_toggle_button_set_active((GtkToggleButton*)gtk_builder_get_object(builder, "IDC_CHECK_GATEWAY"), config.AutoGateway);
gtk_toggle_button_set_active((GtkToggleButton*)gtk_builder_get_object(builder, "IDC_CHECK_DNS1"), config.AutoDNS1);
gtk_toggle_button_set_active((GtkToggleButton*)gtk_builder_get_object(builder, "IDC_CHECK_DNS2"), config.AutoDNS2);
OnAutoMaskChanged((GtkToggleButton*)gtk_builder_get_object(builder, "IDC_CHECK_SUBNET"), nullptr);
OnAutoGatewayChanged((GtkToggleButton*)gtk_builder_get_object(builder, "IDC_CHECK_GATEWAY"), nullptr);
OnAutoDNS1Changed((GtkToggleButton*)gtk_builder_get_object(builder, "IDC_CHECK_DNS1"), nullptr);
OnAutoDNS2Changed((GtkToggleButton*)gtk_builder_get_object(builder, "IDC_CHECK_DNS2"), nullptr);
}
else
{
gtk_widget_set_sensitive((GtkWidget*)gtk_builder_get_object(builder, "IDC_IPADDRESS_IP"), false);
IPControl_SetValue((GtkEntry*)gtk_builder_get_object(builder, "IDC_IPADDRESS_IP"), {0});
gtk_widget_set_sensitive((GtkWidget*)gtk_builder_get_object(builder, "IDC_CHECK_SUBNET"), false);
gtk_widget_set_sensitive((GtkWidget*)gtk_builder_get_object(builder, "IDC_CHECK_GATEWAY"), false);
gtk_widget_set_sensitive((GtkWidget*)gtk_builder_get_object(builder, "IDC_CHECK_DNS1"), false);
gtk_widget_set_sensitive((GtkWidget*)gtk_builder_get_object(builder, "IDC_CHECK_DNS2"), false);
gtk_toggle_button_set_active((GtkToggleButton*)gtk_builder_get_object(builder, "IDC_CHECK_SUBNET"), true);
gtk_toggle_button_set_active((GtkToggleButton*)gtk_builder_get_object(builder, "IDC_CHECK_GATEWAY"), true);
gtk_toggle_button_set_active((GtkToggleButton*)gtk_builder_get_object(builder, "IDC_CHECK_DNS1"), true);
gtk_toggle_button_set_active((GtkToggleButton*)gtk_builder_get_object(builder, "IDC_CHECK_DNS2"), true);
IPControl_Enable((GtkEntry*)gtk_builder_get_object(builder, "IDC_IPADDRESS_SUBNET"), false, config.Mask);
IPControl_Enable((GtkEntry*)gtk_builder_get_object(builder, "IDC_IPADDRESS_GATEWAY"), false, config.Gateway);
IPControl_Enable((GtkEntry*)gtk_builder_get_object(builder, "IDC_IPADDRESS_DNS1"), false, config.DNS1);
IPControl_Enable((GtkEntry*)gtk_builder_get_object(builder, "IDC_IPADDRESS_DNS2"), false, config.DNS2);
}
}
void OnInitDialog()
{
gint idx = 0;
static int initialized = 0;
LoadConf();
if (initialized)
return;
gtk_combo_box_text_append_text((GtkComboBoxText*)gtk_builder_get_object(builder, "IDC_BAYTYPE"), "Expansion");
gtk_combo_box_text_append_text((GtkComboBoxText*)gtk_builder_get_object(builder, "IDC_BAYTYPE"), "PC Card");
adapters = PCAPAdapter::GetAdapters();
for (size_t i = 0; i < adapters.size(); i++)
{
std::string dev = fmt::format("{}: {}", (char*)NetApiToString(adapters[i].type), adapters[i].name.c_str());
gtk_combo_box_text_append_text((GtkComboBoxText*)gtk_builder_get_object(builder, "IDC_ETHDEV"), dev.c_str());
if (config.EthApi == adapters[i].type && strcmp(adapters[i].guid.c_str(), config.Eth) == 0)
gtk_combo_box_set_active((GtkComboBox*)gtk_builder_get_object(builder, "IDC_ETHDEV"), idx);
idx++;
} }
gtk_toggle_button_set_active((GtkToggleButton*)gtk_builder_get_object(builder, "IDC_CHECK_DHCP"), config.InterceptDHCP); static IP_Address IPControl_GetValue(wxTextCtrl* ctl)
OnInterceptChanged((GtkToggleButton*)gtk_builder_get_object(builder, "IDC_CHECK_DHCP"), nullptr);
gtk_entry_set_text((GtkEntry*)gtk_builder_get_object(builder, "IDC_HDDFILE"), config.Hdd);
//HDDSpin
gtk_spin_button_set_range((GtkSpinButton*)gtk_builder_get_object(builder, "IDC_HDDSIZE_SPIN"), HDD_MIN_GB, HDD_MAX_GB);
gtk_spin_button_set_increments((GtkSpinButton*)gtk_builder_get_object(builder, "IDC_HDDSIZE_SPIN"), 1, 10);
gtk_spin_button_set_value((GtkSpinButton*)gtk_builder_get_object(builder, "IDC_HDDSIZE_SPIN"), config.HddSize / 1024);
//HDDSlider
gtk_range_set_range((GtkRange*)gtk_builder_get_object(builder, "IDC_HDDSIZE_SLIDER"), HDD_MIN_GB, HDD_MAX_GB);
gtk_range_set_increments((GtkRange*)gtk_builder_get_object(builder, "IDC_HDDSIZE_SLIDER"), 1, 10);
gtk_scale_add_mark((GtkScale*)gtk_builder_get_object(builder, "IDC_HDDSIZE_SLIDER"), HDD_MIN_GB, GTK_POS_BOTTOM, (std::to_string(HDD_MIN_GB) + " GiB").c_str());
gtk_scale_add_mark((GtkScale*)gtk_builder_get_object(builder, "IDC_HDDSIZE_SLIDER"), HDD_MAX_GB, GTK_POS_BOTTOM, (std::to_string(HDD_MAX_GB) + " GiB").c_str());
for (int i = 15; i < HDD_MAX_GB; i += 5)
{ {
gtk_scale_add_mark((GtkScale*)gtk_builder_get_object(builder, "IDC_HDDSIZE_SLIDER"), i, GTK_POS_BOTTOM, nullptr); IP_Address ret;
if (4 == wxSscanf(ctl->GetValue(), "%hhu.%hhu.%hhu.%hhu", &ret.bytes[0], &ret.bytes[1], &ret.bytes[2], &ret.bytes[3]))
return ret;
Console.Error("Invalid IP address entered");
return {};
} }
gtk_range_set_value((GtkRange*)gtk_builder_get_object(builder, "IDC_HDDSIZE_SLIDER"), config.HddSize / 1024); struct IPInputWithAutoCheck
//Checkboxes
gtk_toggle_button_set_active((GtkToggleButton*)gtk_builder_get_object(builder, "IDC_ETHENABLED"),
config.ethEnable);
gtk_toggle_button_set_active((GtkToggleButton*)gtk_builder_get_object(builder, "IDC_HDDENABLED"),
config.hddEnable);
initialized = 1;
}
void OnBrowse(GtkButton* button, gpointer usr_data)
{
ghc::filesystem::path inis(EmuFolders::Settings.ToString().ToStdString());
static const wxChar* hddFilterType = L"HDD|*.raw;*.RAW";
wxFileDialog ctrl(nullptr, _("HDD Image File"), EmuFolders::Settings.ToString(), HDD_DEF,
(wxString)hddFilterType + L"|" + _("All Files (*.*)") + L"|*.*", wxFD_SAVE);
if (ctrl.ShowModal() != wxID_CANCEL)
{ {
ghc::filesystem::path hddFile(ctrl.GetPath().ToStdString()); wxTextCtrl* m_ip;
wxCheckBox* m_auto;
if (ghc::filesystem::exists(hddFile)) void create(int col, wxWindow* window, wxGridBagSizer* sizer, const wxString& label)
{ {
//Get file size auto* label_box = new wxStaticText(window, wxID_ANY, label);
int filesizeGb = ghc::filesystem::file_size(hddFile) / (1024 * 1024 * 1024); m_ip = new wxTextCtrl(window, wxID_ANY);
m_auto = new wxCheckBox(window, wxID_ANY, _("Auto"));
gtk_range_set_value((GtkRange*)gtk_builder_get_object(builder, "IDC_HDDSIZE_SLIDER"), filesizeGb); sizer->Add(label_box, wxGBPosition(col, 0), wxDefaultSpan, wxALIGN_RIGHT | wxALIGN_CENTRE_VERTICAL);
gtk_spin_button_set_value((GtkSpinButton*)gtk_builder_get_object(builder, "IDC_HDDSIZE_SPIN"), filesizeGb); sizer->Add(m_ip, wxGBPosition(col, 1), wxDefaultSpan, wxEXPAND);
sizer->Add(m_auto, wxGBPosition(col, 2), wxDefaultSpan, wxEXPAND);
} }
void setEnabled(bool enabled)
{
m_auto->Enable(enabled);
m_ip->Enable(enabled && !m_auto->GetValue());
}
void load(const IP_Address& ip, bool is_auto)
{
IPControl_SetValue(m_ip, ip);
m_auto->SetValue(is_auto);
}
void save(IP_Address& ip, int& is_auto)
{
ip = IPControl_GetValue(m_ip);
is_auto = m_auto->GetValue();
}
};
wxCheckBox* m_eth_enable;
wxChoice* m_eth_adapter;
std::vector<AdapterEntry> m_adapter_list;
wxCheckBox* m_intercept_dhcp;
wxTextCtrl* m_ps2_address;
IPInputWithAutoCheck m_subnet_mask;
IPInputWithAutoCheck m_gateway_address;
IPInputWithAutoCheck m_dns1_address;
IPInputWithAutoCheck m_dns2_address;
if (hddFile.parent_path() == inis) wxCheckBox* m_hdd_enable;
hddFile = hddFile.filename(); wxFilePickerCtrl* m_hdd_file;
wxSpinCtrl* m_hdd_size_spin;
wxSlider* m_hdd_size_slider;
gtk_entry_set_text((GtkEntry*)gtk_builder_get_object(builder, "IDC_HDDFILE"), hddFile.c_str()); public:
} DEV9Dialog()
} : wxDialog(nullptr, wxID_ANY, _("Network and HDD Settings"), wxDefaultPosition, wxDefaultSize, wxCAPTION | wxCLOSE_BOX)
void OnSpin(GtkSpinButton* spin, gpointer usr_data)
{
gtk_range_set_value((GtkRange*)gtk_builder_get_object(builder, "IDC_HDDSIZE_SLIDER"),
gtk_spin_button_get_value(spin));
}
void OnSlide(GtkRange* range, gpointer usr_data)
{
gtk_spin_button_set_value((GtkSpinButton*)gtk_builder_get_object(builder, "IDC_HDDSIZE_SPIN"),
gtk_range_get_value(range));
}
void OnOk()
{
int ethIndex = gtk_combo_box_get_active((GtkComboBox*)gtk_builder_get_object(builder, "IDC_ETHDEV"));
if (ethIndex != -1)
{ {
strcpy(config.Eth, adapters[ethIndex].guid.c_str()); auto* padding = new wxBoxSizer(wxVERTICAL);
config.EthApi = adapters[ethIndex].type; auto* top_box = new wxBoxSizer(wxVERTICAL);
// Ethernet section
auto* eth_section = new wxCollapsiblePane(this, wxID_ANY, _("Ethernet"));
auto* eth_pane = eth_section->GetPane();
auto* eth_sizer = new wxBoxSizer(wxVERTICAL);
m_eth_enable = new wxCheckBox(eth_pane, wxID_ANY, _("Enabled"));
eth_sizer->Add(m_eth_enable);
eth_sizer->AddSpacer(5);
auto* eth_adapter_box = new wxGridBagSizer(5, 5);
auto* eth_adapter_label = new wxStaticText(eth_pane, wxID_ANY, _("Ethernet Device:"));
m_adapter_list = PCAPAdapter::GetAdapters();
wxArrayString adapter_name_list;
adapter_name_list.Add("");
for (const AdapterEntry& adapter : m_adapter_list)
adapter_name_list.Add(wxString::Format(_("%s (%s)"), adapter.name, NetApiToWxString(adapter.type)));
m_eth_adapter = new wxChoice(eth_pane, wxID_ANY, wxDefaultPosition, wxDefaultSize, adapter_name_list);
auto* intercept_dhcp_label = new wxStaticText(eth_pane, wxID_ANY, _("Intercept DHCP:"));
m_intercept_dhcp = new wxCheckBox(eth_pane, wxID_ANY, _("Enabled"));
auto* ps2_addr_label = new wxStaticText(eth_pane, wxID_ANY, _("PS2 Address:"));
m_ps2_address = new wxTextCtrl(eth_pane, wxID_ANY);
m_ps2_address->SetMinSize(wxSize(150, -1));
eth_adapter_box->Add(eth_adapter_label, wxGBPosition(0, 0), wxDefaultSpan, wxALIGN_RIGHT | wxALIGN_CENTRE_VERTICAL);
eth_adapter_box->Add(intercept_dhcp_label, wxGBPosition(1, 0), wxDefaultSpan, wxALIGN_RIGHT | wxALIGN_CENTRE_VERTICAL);
eth_adapter_box->Add(ps2_addr_label, wxGBPosition(2, 0), wxDefaultSpan, wxALIGN_RIGHT | wxALIGN_CENTRE_VERTICAL);
eth_adapter_box->Add(m_eth_adapter, wxGBPosition(0, 1), wxGBSpan(1, 2), wxEXPAND);
eth_adapter_box->Add(m_intercept_dhcp, wxGBPosition(1, 1), wxDefaultSpan, wxEXPAND);
eth_adapter_box->Add(m_ps2_address, wxGBPosition(2, 1), wxDefaultSpan, wxEXPAND);
m_subnet_mask .create(3, eth_pane, eth_adapter_box, _("Subnet Mask:"));
m_gateway_address.create(4, eth_pane, eth_adapter_box, _("Gateway Address:"));
m_dns1_address .create(5, eth_pane, eth_adapter_box, _("DNS1 Address:"));
m_dns2_address .create(6, eth_pane, eth_adapter_box, _("DNS2 Address:"));
eth_adapter_box->AddGrowableCol(1);
eth_sizer->Add(eth_adapter_box, wxSizerFlags().Expand());
eth_pane->SetSizer(eth_sizer);
// HDD section
auto* hdd_section = new wxCollapsiblePane(this, wxID_ANY, _("Hard Disk Drive"));
auto* hdd_pane = hdd_section->GetPane();
auto* hdd_sizer = new wxBoxSizer(wxVERTICAL);
m_hdd_enable = new wxCheckBox(hdd_pane, wxID_ANY, _("Enabled"));
hdd_sizer->Add(m_hdd_enable);
hdd_sizer->AddSpacer(5);
auto* hdd_grid = new wxFlexGridSizer(2, 0, 5);
hdd_grid->AddGrowableCol(1);
auto* hdd_file_label = new wxStaticText(hdd_pane, wxID_ANY, _("HDD File:"));
m_hdd_file = new wxFilePickerCtrl(hdd_pane, wxID_ANY, wxEmptyString, _("HDD image file"), "HDD|*.raw", wxDefaultPosition, wxDefaultSize, wxFLP_SAVE | wxFLP_USE_TEXTCTRL);
hdd_grid->Add(hdd_file_label, wxSizerFlags().Centre().Right());
hdd_grid->Add(m_hdd_file, wxSizerFlags().Expand());
auto* hdd_size_label = new wxStaticText(hdd_pane, wxID_ANY, _("HDD Size (GiB):"));
m_hdd_size_spin = new wxSpinCtrl(hdd_pane, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, HDD_MIN_GB, HDD_MAX_GB, HDD_MIN_GB);
hdd_grid->Add(hdd_size_label, wxSizerFlags().Centre().Right());
hdd_grid->Add(m_hdd_size_spin, wxSizerFlags().Expand());
m_hdd_size_slider = new wxSlider(hdd_pane, wxID_ANY, HDD_MIN_GB, HDD_MIN_GB, HDD_MAX_GB, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_VALUE_LABEL | wxSL_MIN_MAX_LABELS | wxSL_AUTOTICKS);
m_hdd_size_slider->SetPageSize(10);
for (int i = 15; i < HDD_MAX_GB; i += 5)
m_hdd_size_slider->SetTick(i);
hdd_grid->AddSpacer(0);
hdd_grid->Add(m_hdd_size_slider, wxSizerFlags().Expand());
hdd_sizer->Add(hdd_grid, wxSizerFlags().Expand());
hdd_pane->SetSizer(hdd_sizer);
top_box->Add(eth_section, wxSizerFlags().Expand());
top_box->Add(hdd_section, wxSizerFlags().Expand());
top_box->Add(CreateStdDialogButtonSizer(wxOK | wxCANCEL), wxSizerFlags().Right());
padding->Add(top_box, wxSizerFlags().Expand().Border(wxALL, 5));
SetSizerAndFit(padding);
Bind(wxEVT_CHECKBOX, &DEV9Dialog::OnCheck, this);
Bind(wxEVT_SLIDER, &DEV9Dialog::OnSlide, this);
Bind(wxEVT_SPINCTRL, &DEV9Dialog::OnSpin, this);
} }
config.InterceptDHCP = gtk_toggle_button_get_active((GtkToggleButton*)gtk_builder_get_object(builder, "IDC_CHECK_DHCP")); void Load(const ConfigDEV9& config)
if (config.InterceptDHCP)
{ {
config.PS2IP = IPControl_GetValue((GtkEntry*)gtk_builder_get_object(builder, "IDC_IPADDRESS_IP")); m_eth_enable->SetValue(config.ethEnable);
m_eth_adapter->SetSelection(0);
for (size_t i = 0; i < m_adapter_list.size(); i++)
{
const AdapterEntry& adapter = m_adapter_list[i];
if (adapter.type == config.EthApi && adapter.name == config.Eth)
{
m_eth_adapter->SetSelection(i + 1);
break;
}
}
m_intercept_dhcp->SetValue(config.InterceptDHCP);
IPControl_SetValue(m_ps2_address, config.PS2IP);
m_subnet_mask .load(config.Mask, config.AutoMask);
m_gateway_address.load(config.Gateway, config.AutoGateway);
m_dns1_address .load(config.DNS1, config.AutoDNS1);
m_dns2_address .load(config.DNS2, config.AutoDNS2);
config.AutoMask = gtk_toggle_button_get_active((GtkToggleButton*)gtk_builder_get_object(builder, "IDC_CHECK_SUBNET")); m_hdd_enable->SetValue(config.hddEnable);
if (!config.AutoMask) m_hdd_file->SetInitialDirectory(config.Hdd);
config.Mask = IPControl_GetValue((GtkEntry*)gtk_builder_get_object(builder, "IDC_IPADDRESS_SUBNET")); m_hdd_file->SetPath(config.Hdd);
m_hdd_size_spin->SetValue(config.HddSize / 1024);
m_hdd_size_slider->SetValue(config.HddSize / 1024);
config.AutoGateway = gtk_toggle_button_get_active((GtkToggleButton*)gtk_builder_get_object(builder, "IDC_CHECK_GATEWAY")); UpdateEnable();
if (!config.AutoGateway)
config.Gateway = IPControl_GetValue((GtkEntry*)gtk_builder_get_object(builder, "IDC_IPADDRESS_GATEWAY"));
config.AutoDNS1 = gtk_toggle_button_get_active((GtkToggleButton*)gtk_builder_get_object(builder, "IDC_CHECK_DNS1"));
if (!config.AutoDNS1)
config.DNS1 = IPControl_GetValue((GtkEntry*)gtk_builder_get_object(builder, "IDC_IPADDRESS_DNS1"));
config.AutoDNS2 = gtk_toggle_button_get_active((GtkToggleButton*)gtk_builder_get_object(builder, "IDC_CHECK_DNS2"));
if (!config.AutoDNS2)
config.DNS2 = IPControl_GetValue((GtkEntry*)gtk_builder_get_object(builder, "IDC_IPADDRESS_DNS2"));
} }
strcpy(config.Hdd, gtk_entry_get_text((GtkEntry*)gtk_builder_get_object(builder, "IDC_HDDFILE"))); void Save(ConfigDEV9& config)
config.HddSize = gtk_spin_button_get_value((GtkSpinButton*)gtk_builder_get_object(builder, "IDC_HDDSIZE_SPIN")) * 1024;
config.ethEnable = gtk_toggle_button_get_active((GtkToggleButton*)gtk_builder_get_object(builder, "IDC_ETHENABLED"));
config.hddEnable = gtk_toggle_button_get_active((GtkToggleButton*)gtk_builder_get_object(builder, "IDC_HDDENABLED"));
ghc::filesystem::path hddPath(config.Hdd);
if (hddPath.is_relative())
{ {
ghc::filesystem::path path(EmuFolders::Settings.ToString().wx_str()); config.ethEnable = m_eth_enable->GetValue();
hddPath = path / hddPath; int eth = m_eth_adapter->GetSelection();
if (eth)
{
wxStrncpy(config.Eth, m_adapter_list[eth - 1].name, ArraySize(config.Eth) - 1);
config.EthApi = m_adapter_list[eth - 1].type;
}
else
{
config.Eth[0] = 0;
config.EthApi = NetApi::Unset;
}
config.InterceptDHCP = m_intercept_dhcp->GetValue();
config.PS2IP = IPControl_GetValue(m_ps2_address);
m_subnet_mask .save(config.Mask, config.AutoMask);
m_gateway_address.save(config.Gateway, config.AutoGateway);
m_dns1_address .save(config.DNS1, config.AutoDNS1);
m_dns2_address .save(config.DNS2, config.AutoDNS2);
config.hddEnable = m_hdd_enable->GetValue();
wxStrncpy(config.Hdd, m_hdd_file->GetPath(), ArraySize(config.Hdd) - 1);
config.HddSize = m_hdd_size_spin->GetValue() * 1024;
} }
if (config.hddEnable && !ghc::filesystem::exists(hddPath)) void UpdateEnable()
{ {
HddCreate hddCreator; bool eth_enable = m_eth_enable->GetValue();
hddCreator.filePath = hddPath; bool hdd_enable = m_hdd_enable->GetValue();
hddCreator.neededSize = config.HddSize; bool dhcp_enable = eth_enable && m_intercept_dhcp->GetValue();
hddCreator.Start();
m_eth_adapter->Enable(eth_enable);
m_intercept_dhcp->Enable(eth_enable);
m_ps2_address->Enable(dhcp_enable);
m_subnet_mask.setEnabled(dhcp_enable);
m_gateway_address.setEnabled(dhcp_enable);
m_dns1_address.setEnabled(dhcp_enable);
m_dns2_address.setEnabled(dhcp_enable);
m_hdd_file->Enable(hdd_enable);
m_hdd_size_spin->Enable(hdd_enable);
m_hdd_size_slider->Enable(hdd_enable);
} }
SaveConf(); void OnCheck(wxCommandEvent&)
} {
UpdateEnable();
}
void OnSlide(wxCommandEvent&)
{
m_hdd_size_spin->SetValue(m_hdd_size_slider->GetValue());
}
void OnSpin(wxCommandEvent&)
{
m_hdd_size_slider->SetValue(m_hdd_size_spin->GetValue());
}
};
void DEV9configure() void DEV9configure()
{ {
ScopedCoreThreadPause paused_core; ScopedCoreThreadPause paused_core;
ConfigDEV9 oldConfig = config;
gtk_init(NULL, NULL); DEV9Dialog dialog;
GError* error = NULL; LoadConf();
if (builder == nullptr) dialog.Load(config);
if (dialog.ShowModal() == wxID_OK)
{ {
builder = gtk_builder_new(); ConfigDEV9 oldConfig = config;
gtk_builder_add_callback_symbols(builder, dialog.Save(config);
"OnInterceptChanged", G_CALLBACK(&OnInterceptChanged),
"OnAutoMaskChanged", G_CALLBACK(&OnAutoMaskChanged), ghc::filesystem::path hddPath(config.Hdd);
"OnAutoGatewayChanged", G_CALLBACK(&OnAutoGatewayChanged),
"OnAutoDNS1Changed", G_CALLBACK(&OnAutoDNS1Changed), if (hddPath.is_relative())
"OnAutoDNS2Changed", G_CALLBACK(&OnAutoDNS2Changed),
"OnBrowse", G_CALLBACK(&OnBrowse),
"OnSpin", G_CALLBACK(&OnSpin),
"OnSlide", G_CALLBACK(&OnSlide), nullptr);
if (!gtk_builder_add_from_resource(builder, "/net/pcsx2/dev9/DEV9/Linux/dev9.ui", &error))
{ {
g_warning("Could not build config ui: %s", error->message); //GHC uses UTF8 on all platforms
g_error_free(error); ghc::filesystem::path path(EmuFolders::Settings.ToString().wx_str());
g_object_unref(G_OBJECT(builder)); hddPath = path / hddPath;
builder = nullptr;
return;
} }
gtk_builder_connect_signals(builder, nullptr);
}
GtkDialog* dlg = GTK_DIALOG(gtk_builder_get_object(builder, "IDD_CONFDLG"));
OnInitDialog();
gint result = gtk_dialog_run(dlg);
switch (result)
{
case -5: //IDOK
OnOk();
break;
case -6: //IDCANCEL
break;
}
gtk_widget_hide(GTK_WIDGET(dlg));
ApplyConfigIfRunning(oldConfig); if (config.hddEnable && !ghc::filesystem::exists(hddPath))
{
HddCreate hddCreator;
hddCreator.filePath = hddPath;
hddCreator.neededSize = config.HddSize;
hddCreator.Start();
}
SaveConf();
ApplyConfigIfRunning(oldConfig);
}
paused_core.AllowResume(); paused_core.AllowResume();
} }

View File

@ -1,515 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.2 -->
<interface>
<requires lib="gtk+" version="3.0"/>
<object class="GtkDialog" id="IDD_CONFDLG">
<property name="can_focus">False</property>
<property name="border_width">5</property>
<property name="title" translatable="yes">Network and HDD Settings</property>
<property name="resizable">False</property>
<property name="type_hint">dialog</property>
<child type="titlebar">
<placeholder/>
</child>
<child internal-child="vbox">
<object class="GtkBox" id="dialog-vbox1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">2</property>
<child internal-child="action_area">
<object class="GtkButtonBox" id="dialog-action_area1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="layout_style">end</property>
<child>
<object class="GtkButton" id="IDOK">
<property name="label" translatable="yes">OK</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="IDCANCEL">
<property name="label" translatable="yes">Cancel</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkGrid">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="hexpand">True</property>
<child>
<object class="GtkComboBoxText" id="IDC_BAYTYPE">
<property name="visible">True</property>
<property name="sensitive">False</property>
<property name="can_focus">False</property>
<property name="hexpand">True</property>
<property name="has_entry">True</property>
<child internal-child="entry">
<object class="GtkEntry">
<property name="can_focus">True</property>
</object>
</child>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label3">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">DEV9 Type: </property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkExpander" id="expander1">
<property name="visible">True</property>
<property name="can_focus">True</property>
<child>
<object class="GtkGrid">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="hexpand">True</property>
<child>
<object class="GtkGrid">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="hexpand">True</property>
<child>
<object class="GtkComboBoxText" id="IDC_ETHDEV">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="hexpand">True</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
<property name="width">2</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label4">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">Ethernet Device: </property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">Intercept DHCP:</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="IDC_CHECK_DHCP">
<property name="label" translatable="yes">Enabled</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="draw_indicator">True</property>
<signal name="toggled" handler="OnInterceptChanged" swapped="no"/>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">1</property>
<property name="width">2</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">PS2 Address:</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">2</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">Subnet Mask:</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">3</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">Gateway Address:</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">4</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">DNS1 Address:</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">5</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">DNS2 Address:</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">6</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="IDC_IPADDRESS_IP">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="max_length">15</property>
<property name="text" translatable="yes">0.0.0.0</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">2</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="IDC_IPADDRESS_SUBNET">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="max_length">15</property>
<property name="text" translatable="yes">0.0.0.0</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">3</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="IDC_IPADDRESS_GATEWAY">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="max_length">15</property>
<property name="text" translatable="yes">0.0.0.0</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">4</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="IDC_IPADDRESS_DNS1">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="max_length">15</property>
<property name="text" translatable="yes">0.0.0.0</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">5</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="IDC_IPADDRESS_DNS2">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="max_length">15</property>
<property name="text" translatable="yes">0.0.0.0</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">6</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="IDC_CHECK_SUBNET">
<property name="label" translatable="yes">Auto</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="draw_indicator">True</property>
<signal name="toggled" handler="OnAutoMaskChanged" swapped="no"/>
</object>
<packing>
<property name="left_attach">2</property>
<property name="top_attach">3</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="IDC_CHECK_GATEWAY">
<property name="label" translatable="yes">Auto</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="draw_indicator">True</property>
<signal name="toggled" handler="OnAutoGatewayChanged" swapped="no"/>
</object>
<packing>
<property name="left_attach">2</property>
<property name="top_attach">4</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="IDC_CHECK_DNS1">
<property name="label" translatable="yes">Auto</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="draw_indicator">True</property>
<signal name="toggled" handler="OnAutoDNS1Changed" swapped="no"/>
</object>
<packing>
<property name="left_attach">2</property>
<property name="top_attach">5</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="IDC_CHECK_DNS2">
<property name="label" translatable="yes">Auto</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="draw_indicator">True</property>
<signal name="toggled" handler="OnAutoDNS2Changed" swapped="no"/>
</object>
<packing>
<property name="left_attach">2</property>
<property name="top_attach">6</property>
</packing>
</child>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="IDC_ETHENABLED">
<property name="label" translatable="yes">Enabled</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
</object>
</child>
<child type="label">
<object class="GtkLabel" id="label1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Ethernet</property>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkExpander" id="expander2">
<property name="visible">True</property>
<property name="can_focus">True</property>
<child>
<object class="GtkGrid">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="hexpand">True</property>
<child>
<object class="GtkCheckButton" id="IDC_HDDENABLED">
<property name="label" translatable="yes">Enabled</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkGrid">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="hexpand">True</property>
<child>
<object class="GtkEntry" id="IDC_HDDFILE">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hexpand">True</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label5">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">HDD File: </property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="IDC_BROWSE">
<property name="label" translatable="yes">Browse</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<signal name="clicked" handler="OnBrowse" swapped="no"/>
</object>
<packing>
<property name="left_attach">2</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label6">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">HDD Size (GiB): </property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
</packing>
</child>
<child>
<object class="GtkSpinButton" id="IDC_HDDSIZE_SPIN">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hexpand">True</property>
<signal name="value-changed" handler="OnSpin" swapped="no"/>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">1</property>
<property name="width">2</property>
</packing>
</child>
<child>
<object class="GtkScale" id="IDC_HDDSIZE_SLIDER">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hexpand">True</property>
<property name="round_digits">0</property>
<property name="digits">0</property>
<property name="value_pos">bottom</property>
<signal name="value-changed" handler="OnSlide" swapped="no"/>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">2</property>
<property name="width">2</property>
</packing>
</child>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
</packing>
</child>
</object>
</child>
<child type="label">
<object class="GtkLabel" id="label2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Hard Disk Drive</property>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">3</property>
</packing>
</child>
</object>
</child>
<action-widgets>
<action-widget response="-5">IDOK</action-widget>
<action-widget response="-6">IDCANCEL</action-widget>
</action-widgets>
</object>
</interface>

View File

@ -163,18 +163,18 @@ void TermNet()
} }
} }
const char* NetApiToString(NetApi api) const wxChar* NetApiToWxString(NetApi api)
{ {
switch (api) switch (api)
{ {
case NetApi::PCAP_Bridged: case NetApi::PCAP_Bridged:
return "PCAP (Bridged)"; return _("PCAP Bridged");
case NetApi::PCAP_Switched: case NetApi::PCAP_Switched:
return "PCAP (Switched)"; return _("PCAP Switched");
case NetApi::TAP: case NetApi::TAP:
return "TAP"; return _("TAP");
default: default:
return "UNK"; return _("UNK");
} }
} }

View File

@ -140,5 +140,5 @@ void InitNet();
void ReconfigureLiveNet(ConfigDEV9* oldConfig); void ReconfigureLiveNet(ConfigDEV9* oldConfig);
void TermNet(); void TermNet();
const char* NetApiToString(NetApi api); const wxChar* NetApiToWxString(NetApi api);
const wchar_t* NetApiToWstring(NetApi api); const wchar_t* NetApiToWstring(NetApi api);