From 7a165db94f7f67e62a3d7f73ff56f41c23f22d6d Mon Sep 17 00:00:00 2001 From: JosJuice Date: Sun, 2 Oct 2016 16:33:59 +0200 Subject: [PATCH 1/4] DolphinWX: Less duplication between GetTraversalPort/Server They now also return their results the regular way. --- .../DolphinWX/NetPlay/NetPlaySetupFrame.cpp | 43 +++++++++---------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/Source/Core/DolphinWX/NetPlay/NetPlaySetupFrame.cpp b/Source/Core/DolphinWX/NetPlay/NetPlaySetupFrame.cpp index 7a59288682..a2c3312b06 100644 --- a/Source/Core/DolphinWX/NetPlay/NetPlaySetupFrame.cpp +++ b/Source/Core/DolphinWX/NetPlay/NetPlaySetupFrame.cpp @@ -23,20 +23,25 @@ #include "DolphinWX/NetPlay/NetWindow.h" #include "DolphinWX/WxUtils.h" -static void GetTraversalPort(IniFile::Section& section, std::string* port) +static std::string GetFromINI(IniFile::Section& section, const std::string& key, + const std::string& default_value) { - section.Get("TraversalPort", port, "6262"); - port->erase(std::remove(port->begin(), port->end(), ' '), port->end()); - if (port->empty()) - *port = "6262"; + std::string result; + section.Get(key, &result, default_value); + result.erase(std::remove(result.begin(), result.end(), ' '), result.end()); + if (result.empty()) + return default_value; + return result; } -static void GetTraversalServer(IniFile::Section& section, std::string* server) +static std::string GetTraversalPort(IniFile::Section& section) { - section.Get("TraversalServer", server, "stun.dolphin-emu.org"); - server->erase(std::remove(server->begin(), server->end(), ' '), server->end()); - if (server->empty()) - *server = "stun.dolphin-emu.org"; + return GetFromINI(section, "TraversalPort", "6262"); +} + +static std::string GetTraversalServer(IniFile::Section& section) +{ + return GetFromINI(section, "TraversalServer", "stun.dolphin-emu.org"); } NetPlaySetupFrame::NetPlaySetupFrame(wxWindow* const parent, const CGameListCtrl* const game_list) @@ -98,10 +103,8 @@ NetPlaySetupFrame::NetPlaySetupFrame(wxWindow* const parent, const CGameListCtrl m_direct_traversal->Select(DIRECT_CHOICE); } - std::string centralPort; - GetTraversalPort(netplay_section, ¢ralPort); - std::string centralServer; - GetTraversalServer(netplay_section, ¢ralServer); + std::string centralPort = GetTraversalPort(netplay_section); + std::string centralServer = GetTraversalServer(netplay_section); m_traversal_lbl = new wxStaticText(panel, wxID_ANY, _("Traversal Server:") + " " + centralServer + ":" + centralPort); @@ -312,13 +315,11 @@ void NetPlaySetupFrame::MakeNetPlayDiag(int port, const std::string& game, bool inifile.Load(File::GetUserPath(F_DOLPHINCONFIG_IDX)); IniFile::Section& netplay_section = *inifile.GetOrCreateSection("NetPlay"); - std::string centralPortString; - GetTraversalPort(netplay_section, ¢ralPortString); + std::string centralPortString = GetTraversalPort(netplay_section); unsigned long int centralPort; StrToWxStr(centralPortString).ToULong(¢ralPort); - std::string centralServer; - GetTraversalServer(netplay_section, ¢ralServer); + std::string centralServer = GetTraversalServer(netplay_section); netplay_client = new NetPlayClient(ip, (u16)port, npd, WxStrToStr(m_nickname_text->GetValue()), trav, centralServer, (u16)centralPort); @@ -394,13 +395,11 @@ void NetPlaySetupFrame::DoHost() m_host_port_text->GetValue().ToULong(&listen_port); } - std::string centralPortString; - GetTraversalPort(netplay_section, ¢ralPortString); + std::string centralPortString = GetTraversalPort(netplay_section); unsigned long int centralPort; StrToWxStr(centralPortString).ToULong(¢ralPort); - std::string centralServer; - GetTraversalServer(netplay_section, ¢ralServer); + std::string centralServer = GetTraversalServer(netplay_section); netplay_server = new NetPlayServer((u16)listen_port, trav, centralServer, (u16)centralPort); if (netplay_server->is_connected) From abc39f6c6feda5e64d93c01a7a1350033c067c5f Mon Sep 17 00:00:00 2001 From: JosJuice Date: Sun, 2 Oct 2016 16:36:12 +0200 Subject: [PATCH 2/4] DolphinWX: Use constants for default traversal server --- Source/Core/DolphinWX/NetPlay/NetPlaySetupFrame.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Source/Core/DolphinWX/NetPlay/NetPlaySetupFrame.cpp b/Source/Core/DolphinWX/NetPlay/NetPlaySetupFrame.cpp index a2c3312b06..e989b5be94 100644 --- a/Source/Core/DolphinWX/NetPlay/NetPlaySetupFrame.cpp +++ b/Source/Core/DolphinWX/NetPlay/NetPlaySetupFrame.cpp @@ -23,6 +23,9 @@ #include "DolphinWX/NetPlay/NetWindow.h" #include "DolphinWX/WxUtils.h" +static const std::string DEFAULT_TRAVERSAL_SERVER = "stun.dolphin-emu.org"; +static const std::string DEFAULT_TRAVERSAL_PORT = "6262"; + static std::string GetFromINI(IniFile::Section& section, const std::string& key, const std::string& default_value) { @@ -36,12 +39,12 @@ static std::string GetFromINI(IniFile::Section& section, const std::string& key, static std::string GetTraversalPort(IniFile::Section& section) { - return GetFromINI(section, "TraversalPort", "6262"); + return GetFromINI(section, "TraversalPort", DEFAULT_TRAVERSAL_PORT); } static std::string GetTraversalServer(IniFile::Section& section) { - return GetFromINI(section, "TraversalServer", "stun.dolphin-emu.org"); + return GetFromINI(section, "TraversalServer", DEFAULT_TRAVERSAL_SERVER); } NetPlaySetupFrame::NetPlaySetupFrame(wxWindow* const parent, const CGameListCtrl* const game_list) @@ -452,8 +455,8 @@ void NetPlaySetupFrame::OnResetTraversal(wxCommandEvent& event) const std::string dolphin_ini = File::GetUserPath(F_DOLPHINCONFIG_IDX); inifile.Load(dolphin_ini); IniFile::Section& netplay_section = *inifile.GetOrCreateSection("NetPlay"); - netplay_section.Set("TraversalServer", (std::string) "stun.dolphin-emu.org"); - netplay_section.Set("TraversalPort", (std::string) "6262"); + netplay_section.Set("TraversalServer", DEFAULT_TRAVERSAL_SERVER); + netplay_section.Set("TraversalPort", DEFAULT_TRAVERSAL_PORT); inifile.Save(dolphin_ini); m_traversal_lbl->SetLabelText(_("Traversal Server: ") + "stun.dolphin-emu.org:6262"); From 337f573484a2f4bef759ad0c4052d80478bf056e Mon Sep 17 00:00:00 2001 From: JosJuice Date: Sun, 2 Oct 2016 16:43:43 +0200 Subject: [PATCH 3/4] DolphinWX: Less duplication for setting traversal server label --- .../Core/DolphinWX/NetPlay/NetPlaySetupFrame.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/Source/Core/DolphinWX/NetPlay/NetPlaySetupFrame.cpp b/Source/Core/DolphinWX/NetPlay/NetPlaySetupFrame.cpp index e989b5be94..0ab8572516 100644 --- a/Source/Core/DolphinWX/NetPlay/NetPlaySetupFrame.cpp +++ b/Source/Core/DolphinWX/NetPlay/NetPlaySetupFrame.cpp @@ -47,6 +47,13 @@ static std::string GetTraversalServer(IniFile::Section& section) return GetFromINI(section, "TraversalServer", DEFAULT_TRAVERSAL_SERVER); } +static wxString GetTraversalLabelText(IniFile::Section& section) +{ + std::string server = GetTraversalServer(section); + std::string port = GetTraversalPort(section); + return wxString::Format(_("Traversal Server: %s"), (server + ":" + port).c_str()); +} + NetPlaySetupFrame::NetPlaySetupFrame(wxWindow* const parent, const CGameListCtrl* const game_list) : wxFrame(parent, wxID_ANY, _("Dolphin NetPlay Setup")), m_game_list(game_list) { @@ -106,11 +113,7 @@ NetPlaySetupFrame::NetPlaySetupFrame(wxWindow* const parent, const CGameListCtrl m_direct_traversal->Select(DIRECT_CHOICE); } - std::string centralPort = GetTraversalPort(netplay_section); - std::string centralServer = GetTraversalServer(netplay_section); - - m_traversal_lbl = new wxStaticText(panel, wxID_ANY, _("Traversal Server:") + " " + - centralServer + ":" + centralPort); + m_traversal_lbl = new wxStaticText(panel, wxID_ANY, GetTraversalLabelText(netplay_section)); } // tabs m_notebook = new wxNotebook(panel, wxID_ANY); @@ -459,7 +462,7 @@ void NetPlaySetupFrame::OnResetTraversal(wxCommandEvent& event) netplay_section.Set("TraversalPort", DEFAULT_TRAVERSAL_PORT); inifile.Save(dolphin_ini); - m_traversal_lbl->SetLabelText(_("Traversal Server: ") + "stun.dolphin-emu.org:6262"); + m_traversal_lbl->SetLabelText(GetTraversalLabelText(netplay_section)); } void NetPlaySetupFrame::OnTraversalListenPortChanged(wxCommandEvent& event) From 6ff2bd324331f726d7509a587075c4f229a3ddb0 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Sun, 2 Oct 2016 17:04:03 +0200 Subject: [PATCH 4/4] DolphinWX: Delete traversal settings when pressing Reset Deleting instead of overwriting makes the INI cleaner. Also, in case we change defaults in the future, users will get the new default when using a new version even if they have pressed the Reset button in an older version. --- Source/Core/DolphinWX/NetPlay/NetPlaySetupFrame.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Core/DolphinWX/NetPlay/NetPlaySetupFrame.cpp b/Source/Core/DolphinWX/NetPlay/NetPlaySetupFrame.cpp index 0ab8572516..a2ab816964 100644 --- a/Source/Core/DolphinWX/NetPlay/NetPlaySetupFrame.cpp +++ b/Source/Core/DolphinWX/NetPlay/NetPlaySetupFrame.cpp @@ -458,8 +458,8 @@ void NetPlaySetupFrame::OnResetTraversal(wxCommandEvent& event) const std::string dolphin_ini = File::GetUserPath(F_DOLPHINCONFIG_IDX); inifile.Load(dolphin_ini); IniFile::Section& netplay_section = *inifile.GetOrCreateSection("NetPlay"); - netplay_section.Set("TraversalServer", DEFAULT_TRAVERSAL_SERVER); - netplay_section.Set("TraversalPort", DEFAULT_TRAVERSAL_PORT); + netplay_section.Delete("TraversalServer"); + netplay_section.Delete("TraversalPort"); inifile.Save(dolphin_ini); m_traversal_lbl->SetLabelText(GetTraversalLabelText(netplay_section));