diff --git a/Source/Core/Common/Config/Section.cpp b/Source/Core/Common/Config/Section.cpp index 7db2c557ea..bb9fcef0e3 100644 --- a/Source/Core/Common/Config/Section.cpp +++ b/Source/Core/Common/Config/Section.cpp @@ -54,6 +54,11 @@ void Section::Set(const std::string& key, const std::string& value) } } +void Section::Set(const std::string& key, u16 newValue) +{ + Section::Set(key, StringFromFormat("0x%04x", newValue)); +} + void Section::Set(const std::string& key, u32 newValue) { Section::Set(key, StringFromFormat("0x%08x", newValue)); @@ -124,6 +129,18 @@ bool Section::Get(const std::string& key, int* value, int defaultValue) const return false; } +bool Section::Get(const std::string& key, u16* value, u16 defaultValue) const +{ + std::string temp; + bool retval = Get(key, &temp); + + if (retval && TryParse(temp, value)) + return true; + + *value = defaultValue; + return false; +} + bool Section::Get(const std::string& key, u32* value, u32 defaultValue) const { std::string temp; diff --git a/Source/Core/Common/Config/Section.h b/Source/Core/Common/Config/Section.h index 0a4662d156..948ebd67d4 100644 --- a/Source/Core/Common/Config/Section.h +++ b/Source/Core/Common/Config/Section.h @@ -35,6 +35,7 @@ public: // Setters virtual void Set(const std::string& key, const std::string& value); + void Set(const std::string& key, u16 newValue); void Set(const std::string& key, u32 newValue); void Set(const std::string& key, float newValue); void Set(const std::string& key, double newValue); @@ -57,6 +58,7 @@ public: const std::string& default_value = NULL_STRING) const; bool Get(const std::string& key, int* value, int defaultValue = 0) const; + bool Get(const std::string& key, u16* value, u16 defaultValue = 0) const; bool Get(const std::string& key, u32* value, u32 defaultValue = 0) const; bool Get(const std::string& key, bool* value, bool defaultValue = false) const; bool Get(const std::string& key, float* value, float defaultValue = 0.0f) const; diff --git a/Source/Core/Core/CMakeLists.txt b/Source/Core/Core/CMakeLists.txt index 761eee33e3..109cca19c3 100644 --- a/Source/Core/Core/CMakeLists.txt +++ b/Source/Core/Core/CMakeLists.txt @@ -26,6 +26,7 @@ set(SRCS Boot/DolReader.cpp Boot/ElfReader.cpp Config/GraphicsSettings.cpp + Config/NetplaySettings.cpp ConfigLoaders/BaseConfigLoader.cpp ConfigLoaders/GameConfigLoader.cpp ConfigLoaders/IsSettingSaveable.cpp diff --git a/Source/Core/Core/Config/NetplaySettings.cpp b/Source/Core/Core/Config/NetplaySettings.cpp new file mode 100644 index 0000000000..3b0082329d --- /dev/null +++ b/Source/Core/Core/Config/NetplaySettings.cpp @@ -0,0 +1,36 @@ +// Copyright 2017 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#include "Core/Config/NetplaySettings.h" + +#include "Common/Config/Config.h" + +namespace Config +{ +static constexpr u16 DEFAULT_LISTEN_PORT = 2626; + +// Configuration Information + +// Main.NetPlay + +const ConfigInfo NETPLAY_TRAVERSAL_SERVER{{System::Main, "NetPlay", "TraversalServer"}, + "stun.dolphin-emu.org"}; +const ConfigInfo NETPLAY_TRAVERSAL_PORT{{System::Main, "NetPlay", "TraversalPort"}, 6262}; +const ConfigInfo NETPLAY_TRAVERSAL_CHOICE{{System::Main, "NetPlay", "TraversalChoice"}, + "direct"}; +const ConfigInfo NETPLAY_HOST_CODE{{System::Main, "NetPlay", "HostCode"}, "00000000"}; + +const ConfigInfo NETPLAY_HOST_PORT{{System::Main, "NetPlay", "HostPort"}, DEFAULT_LISTEN_PORT}; +const ConfigInfo NETPLAY_ADDRESS{{System::Main, "NetPlay", "Address"}, "127.0.0.1"}; +const ConfigInfo NETPLAY_CONNECT_PORT{{System::Main, "NetPlay", "ConnectPort"}, + DEFAULT_LISTEN_PORT}; +const ConfigInfo NETPLAY_LISTEN_PORT{{System::Main, "NetPlay", "ListenPort"}, + DEFAULT_LISTEN_PORT}; + +const ConfigInfo NETPLAY_NICKNAME{{System::Main, "NetPlay", "Nickname"}, "Player"}; +const ConfigInfo NETPLAY_SELECTED_HOST_GAME{ + {System::Main, "NetPlay", "SelectedHostGame"}, ""}; +const ConfigInfo NETPLAY_USE_UPNP{{System::Main, "NetPlay", "UseUPNP"}, false}; + +} // namespace Config diff --git a/Source/Core/Core/Config/NetplaySettings.h b/Source/Core/Core/Config/NetplaySettings.h new file mode 100644 index 0000000000..1978fdeb84 --- /dev/null +++ b/Source/Core/Core/Config/NetplaySettings.h @@ -0,0 +1,32 @@ +// Copyright 2017 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#pragma once + +#include + +#include "Common/CommonTypes.h" +#include "Common/Config/Config.h" + +namespace Config +{ +// Configuration Information + +// Main.NetPlay + +extern const ConfigInfo NETPLAY_TRAVERSAL_SERVER; +extern const ConfigInfo NETPLAY_TRAVERSAL_PORT; +extern const ConfigInfo NETPLAY_TRAVERSAL_CHOICE; +extern const ConfigInfo NETPLAY_HOST_CODE; + +extern const ConfigInfo NETPLAY_HOST_PORT; +extern const ConfigInfo NETPLAY_ADDRESS; +extern const ConfigInfo NETPLAY_CONNECT_PORT; +extern const ConfigInfo NETPLAY_LISTEN_PORT; + +extern const ConfigInfo NETPLAY_NICKNAME; +extern const ConfigInfo NETPLAY_SELECTED_HOST_GAME; +extern const ConfigInfo NETPLAY_USE_UPNP; + +} // namespace Config diff --git a/Source/Core/Core/ConfigLoaders/IsSettingSaveable.cpp b/Source/Core/Core/ConfigLoaders/IsSettingSaveable.cpp index 939f6b778e..0349fa6ed6 100644 --- a/Source/Core/Core/ConfigLoaders/IsSettingSaveable.cpp +++ b/Source/Core/Core/ConfigLoaders/IsSettingSaveable.cpp @@ -17,6 +17,9 @@ bool IsSettingSaveable(const Config::ConfigLocation& config_location) if (config_location.system == Config::System::Logger) return true; + if (config_location.system == Config::System::Main && config_location.section == "NetPlay") + return true; + const static std::vector s_setting_saveable{ // Graphics.Hardware diff --git a/Source/Core/Core/Core.vcxproj b/Source/Core/Core/Core.vcxproj index a5d8c85456..b24a48ef2f 100644 --- a/Source/Core/Core/Core.vcxproj +++ b/Source/Core/Core/Core.vcxproj @@ -46,6 +46,7 @@ + @@ -301,6 +302,7 @@ + diff --git a/Source/Core/Core/Core.vcxproj.filters b/Source/Core/Core/Core.vcxproj.filters index 49b139432a..6839621c7d 100644 --- a/Source/Core/Core/Core.vcxproj.filters +++ b/Source/Core/Core/Core.vcxproj.filters @@ -874,6 +874,9 @@ Config + + Config + IOS\Network\NCD @@ -1523,6 +1526,9 @@ Config + + Config + IOS\Network\NCD diff --git a/Source/Core/DolphinWX/GameListCtrl.cpp b/Source/Core/DolphinWX/GameListCtrl.cpp index 58005099be..4cd9f178f7 100644 --- a/Source/Core/DolphinWX/GameListCtrl.cpp +++ b/Source/Core/DolphinWX/GameListCtrl.cpp @@ -46,6 +46,7 @@ #include "Common/SysConf.h" #include "Common/Thread.h" #include "Core/Boot/Boot.h" +#include "Core/Config/NetplaySettings.h" #include "Core/ConfigManager.h" #include "Core/Core.h" #include "Core/HW/DVD/DVDInterface.h" @@ -1334,20 +1335,13 @@ void GameListCtrl::OnNetPlayHost(wxCommandEvent& WXUNUSED(event)) if (!iso) return; - IniFile ini_file; - const std::string dolphin_ini = File::GetUserPath(F_DOLPHINCONFIG_IDX); - ini_file.Load(dolphin_ini); - IniFile::Section& netplay_section = *ini_file.GetOrCreateSection("NetPlay"); - NetPlayHostConfig config; - config.FromIniConfig(netplay_section); + config.FromConfig(); config.game_name = iso->GetUniqueIdentifier(); config.game_list_ctrl = this; - config.SetDialogInfo(netplay_section, m_parent); - - netplay_section.Set("SelectedHostGame", config.game_name); - ini_file.Save(dolphin_ini); + config.SetDialogInfo(m_parent); + Config::SetBaseOrCurrent(Config::NETPLAY_SELECTED_HOST_GAME, config.game_name); NetPlayLauncher::Host(config); } diff --git a/Source/Core/DolphinWX/NetPlay/NetPlayLauncher.cpp b/Source/Core/DolphinWX/NetPlay/NetPlayLauncher.cpp index eb6bade7a2..307a03385e 100644 --- a/Source/Core/DolphinWX/NetPlay/NetPlayLauncher.cpp +++ b/Source/Core/DolphinWX/NetPlay/NetPlayLauncher.cpp @@ -2,11 +2,12 @@ // Licensed under GPLv2+ // Refer to the license.txt file included. +#include #include #include "Common/CommonTypes.h" -#include "Common/IniFile.h" #include "Common/StringUtil.h" +#include "Core/Config/NetplaySettings.h" #include "DolphinWX/NetPlay/NetPlayLauncher.h" #include "DolphinWX/NetPlay/NetWindow.h" #include "DolphinWX/WxUtils.h" @@ -91,44 +92,14 @@ bool NetPlayLauncher::Join(const NetPlayJoinConfig& config) } } -const std::string NetPlayLaunchConfig::DEFAULT_TRAVERSAL_HOST = "stun.dolphin-emu.org"; - -std::string -NetPlayLaunchConfig::GetTraversalHostFromIniConfig(const IniFile::Section& netplay_section) -{ - std::string host; - - netplay_section.Get("TraversalServer", &host, DEFAULT_TRAVERSAL_HOST); - host = StripSpaces(host); - - if (host.empty()) - return DEFAULT_TRAVERSAL_HOST; - - return host; -} - -u16 NetPlayLaunchConfig::GetTraversalPortFromIniConfig(const IniFile::Section& netplay_section) -{ - std::string port_str; - unsigned long port; - - netplay_section.Get("TraversalPort", &port_str, std::to_string(DEFAULT_TRAVERSAL_PORT)); - StrToWxStr(port_str).ToULong(&port); - - if (port == 0) - port = DEFAULT_TRAVERSAL_PORT; - - return static_cast(port); -} - -void NetPlayLaunchConfig::SetDialogInfo(const IniFile::Section& section, wxWindow* parent) +void NetPlayLaunchConfig::SetDialogInfo(wxWindow* parent) { parent_window = parent; - section.Get("NetWindowPosX", &window_pos.x, window_defaults.GetX()); - section.Get("NetWindowPosY", &window_pos.y, window_defaults.GetY()); - section.Get("NetWindowWidth", &window_pos.width, window_defaults.GetWidth()); - section.Get("NetWindowHeight", &window_pos.height, window_defaults.GetHeight()); + wxConfig::Get()->Read("NetWindowPosX", &window_pos.x, window_defaults.GetX()); + wxConfig::Get()->Read("NetWindowPosY", &window_pos.y, window_defaults.GetY()); + wxConfig::Get()->Read("NetWindowWidth", &window_pos.width, window_defaults.GetWidth()); + wxConfig::Get()->Read("NetWindowHeight", &window_pos.height, window_defaults.GetHeight()); if (window_pos.GetX() == window_defaults.GetX() || window_pos.GetY() == window_defaults.GetY()) { @@ -137,26 +108,20 @@ void NetPlayLaunchConfig::SetDialogInfo(const IniFile::Section& section, wxWindo } } -void NetPlayHostConfig::FromIniConfig(IniFile::Section& netplay_section) +void NetPlayHostConfig::FromConfig() { - netplay_section.Get("Nickname", &player_name, "Player"); + player_name = Config::Get(Config::NETPLAY_NICKNAME); - std::string traversal_choice_setting; - netplay_section.Get("TraversalChoice", &traversal_choice_setting, "direct"); + const std::string traversal_choice_setting = Config::Get(Config::NETPLAY_TRAVERSAL_CHOICE); use_traversal = traversal_choice_setting == "traversal"; if (!use_traversal) { - unsigned long lport = 0; - std::string port_setting; - netplay_section.Get("HostPort", &port_setting, std::to_string(DEFAULT_LISTEN_PORT)); - StrToWxStr(port_setting).ToULong(&lport); - - listen_port = static_cast(lport); + listen_port = Config::Get(Config::NETPLAY_HOST_PORT); } else { - traversal_port = GetTraversalPortFromIniConfig(netplay_section); - traversal_host = GetTraversalHostFromIniConfig(netplay_section); + traversal_port = Config::Get(Config::NETPLAY_TRAVERSAL_PORT); + traversal_host = Config::Get(Config::NETPLAY_TRAVERSAL_SERVER); } -} \ No newline at end of file +} diff --git a/Source/Core/DolphinWX/NetPlay/NetPlayLauncher.h b/Source/Core/DolphinWX/NetPlay/NetPlayLauncher.h index fa245dadc7..ddc92f6f34 100644 --- a/Source/Core/DolphinWX/NetPlay/NetPlayLauncher.h +++ b/Source/Core/DolphinWX/NetPlay/NetPlayLauncher.h @@ -6,7 +6,6 @@ #include #include "Common/CommonTypes.h" -#include "Common/IniFile.h" class GameListCtrl; class wxRect; @@ -15,12 +14,8 @@ class wxWindow; class NetPlayLaunchConfig { public: - static std::string GetTraversalHostFromIniConfig(const IniFile::Section& netplay_section); - static u16 GetTraversalPortFromIniConfig(const IniFile::Section& netplay_section); - void SetDialogInfo(const IniFile::Section& section, wxWindow* parent); + void SetDialogInfo(wxWindow* parent); - static const std::string DEFAULT_TRAVERSAL_HOST; - static constexpr u16 DEFAULT_TRAVERSAL_PORT = 6262; const wxRect window_defaults{wxDefaultCoord, wxDefaultCoord, 768, 768 - 128}; std::string player_name; @@ -35,9 +30,7 @@ public: class NetPlayHostConfig : public NetPlayLaunchConfig { public: - void FromIniConfig(IniFile::Section& netplay_section); - - static constexpr u16 DEFAULT_LISTEN_PORT = 2626; + void FromConfig(); std::string game_name; u16 listen_port = 0; diff --git a/Source/Core/DolphinWX/NetPlay/NetPlaySetupFrame.cpp b/Source/Core/DolphinWX/NetPlay/NetPlaySetupFrame.cpp index 1fd401ea37..0be4d31810 100644 --- a/Source/Core/DolphinWX/NetPlay/NetPlaySetupFrame.cpp +++ b/Source/Core/DolphinWX/NetPlay/NetPlaySetupFrame.cpp @@ -22,16 +22,16 @@ #include "DolphinWX/WxUtils.h" #include "Common/FileUtil.h" -#include "Common/IniFile.h" +#include "Core/Config/NetplaySettings.h" #include "Core/NetPlayClient.h" #include "Core/NetPlayServer.h" namespace { -wxString GetTraversalLabelText(IniFile::Section& section) +wxString GetTraversalLabelText() { - std::string server = NetPlayLaunchConfig::GetTraversalHostFromIniConfig(section); - std::string port = std::to_string(NetPlayLaunchConfig::GetTraversalPortFromIniConfig(section)); + std::string server = Config::Get(Config::NETPLAY_TRAVERSAL_SERVER); + std::string port = std::to_string(Config::Get(Config::NETPLAY_TRAVERSAL_PORT)); return wxString::Format(_("Traversal Server: %s"), (server + ":" + port).c_str()); } } // Anonymous namespace @@ -39,54 +39,28 @@ wxString GetTraversalLabelText(IniFile::Section& section) NetPlaySetupFrame::NetPlaySetupFrame(wxWindow* const parent, const GameListCtrl* const game_list) : wxFrame(parent, wxID_ANY, _("Dolphin NetPlay Setup")), m_game_list(game_list) { - IniFile inifile; - inifile.Load(File::GetUserPath(F_DOLPHINCONFIG_IDX)); - IniFile::Section& netplay_section = *inifile.GetOrCreateSection("NetPlay"); - CreateGUI(); SetIcons(WxUtils::GetDolphinIconBundle()); { - std::string temp; - netplay_section.Get("Nickname", &temp, "Player"); - m_nickname_text->SetValue(StrToWxStr(temp)); - - temp.clear(); - netplay_section.Get("HostCode", &temp, "00000000"); - m_connect_hashcode_text->SetValue(StrToWxStr(temp)); - - temp.clear(); - netplay_section.Get("Address", &temp, "127.0.0.1"); - m_connect_ip_text->SetValue(StrToWxStr(temp)); - - temp.clear(); - netplay_section.Get("ConnectPort", &temp, - std::to_string(NetPlayHostConfig::DEFAULT_LISTEN_PORT)); - m_connect_port_text->SetValue(StrToWxStr(temp)); - - temp.clear(); - netplay_section.Get("HostPort", &temp, std::to_string(NetPlayHostConfig::DEFAULT_LISTEN_PORT)); - m_host_port_text->SetValue(StrToWxStr(temp)); - - temp.clear(); - if (netplay_section.Get("SelectedHostGame", &temp, "")) - m_game_lbox->SetStringSelection(StrToWxStr(temp)); + m_nickname_text->SetValue(StrToWxStr(Config::Get(Config::NETPLAY_NICKNAME))); + m_connect_hashcode_text->SetValue(StrToWxStr(Config::Get(Config::NETPLAY_HOST_CODE))); + m_connect_ip_text->SetValue(StrToWxStr(Config::Get(Config::NETPLAY_ADDRESS))); + m_connect_port_text->SetValue( + StrToWxStr(std::to_string(Config::Get(Config::NETPLAY_CONNECT_PORT)))); + m_host_port_text->SetValue(StrToWxStr(std::to_string(Config::Get(Config::NETPLAY_HOST_PORT)))); + m_game_lbox->SetStringSelection(StrToWxStr(Config::Get(Config::NETPLAY_SELECTED_HOST_GAME))); #ifdef USE_UPNP - bool use_upnp = false; - netplay_section.Get("UseUPNP", &use_upnp, false); - m_upnp_chk->SetValue(use_upnp); + m_upnp_chk->SetValue(Config::Get(Config::NETPLAY_USE_UPNP)); #endif - unsigned int listen_port = 0; - netplay_section.Get("ListenPort", &listen_port, 0); + unsigned int listen_port = Config::Get(Config::NETPLAY_LISTEN_PORT); m_traversal_listen_port_enabled->SetValue(listen_port != 0); m_traversal_listen_port->Enable(m_traversal_listen_port_enabled->IsChecked()); m_traversal_listen_port->SetValue(listen_port); - temp.clear(); - netplay_section.Get("TraversalChoice", &temp, "direct"); - if (temp == "traversal") + if (Config::Get(Config::NETPLAY_TRAVERSAL_CHOICE) == "traversal") { m_direct_traversal->Select(TRAVERSAL_CHOICE); } @@ -95,7 +69,7 @@ NetPlaySetupFrame::NetPlaySetupFrame(wxWindow* const parent, const GameListCtrl* m_direct_traversal->Select(DIRECT_CHOICE); } - m_traversal_lbl->SetLabelText(GetTraversalLabelText(netplay_section)); + m_traversal_lbl->SetLabelText(GetTraversalLabelText()); } Center(); @@ -184,8 +158,7 @@ wxNotebook* NetPlaySetupFrame::CreateNotebookGUI(wxWindow* parent) m_connect_hashcode_text->Hide(); m_client_port_lbl = new wxStaticText(connect_tab, wxID_ANY, _("Port:")); - m_connect_port_text = new wxTextCtrl(connect_tab, wxID_ANY, - std::to_string(NetPlayHostConfig::DEFAULT_LISTEN_PORT)); + m_connect_port_text = new wxTextCtrl(connect_tab, wxID_ANY, ""); wxButton* const connect_btn = new wxButton(connect_tab, wxID_ANY, _("Connect")); connect_btn->Bind(wxEVT_BUTTON, &NetPlaySetupFrame::OnJoin, this); @@ -224,8 +197,7 @@ wxNotebook* NetPlaySetupFrame::CreateNotebookGUI(wxWindow* parent) // host tab { m_host_port_lbl = new wxStaticText(host_tab, wxID_ANY, _("Port:")); - m_host_port_text = - new wxTextCtrl(host_tab, wxID_ANY, std::to_string(NetPlayHostConfig::DEFAULT_LISTEN_PORT)); + m_host_port_text = new wxTextCtrl(host_tab, wxID_ANY, ""); m_traversal_listen_port_enabled = new wxCheckBox(host_tab, wxID_ANY, _("Force Listen Port:")); m_traversal_listen_port = new wxSpinCtrl(host_tab, wxID_ANY, "", wxDefaultPosition, @@ -277,11 +249,6 @@ wxNotebook* NetPlaySetupFrame::CreateNotebookGUI(wxWindow* parent) NetPlaySetupFrame::~NetPlaySetupFrame() { - IniFile inifile; - const std::string dolphin_ini = File::GetUserPath(F_DOLPHINCONFIG_IDX); - inifile.Load(dolphin_ini); - IniFile::Section& netplay_section = *inifile.GetOrCreateSection("NetPlay"); - std::string travChoice; switch (m_direct_traversal->GetSelection()) { @@ -293,25 +260,28 @@ NetPlaySetupFrame::~NetPlaySetupFrame() break; } - netplay_section.Set("TraversalChoice", travChoice); - netplay_section.Set("Nickname", WxStrToStr(m_nickname_text->GetValue())); + Config::SetBaseOrCurrent(Config::NETPLAY_TRAVERSAL_CHOICE, travChoice); + Config::SetBaseOrCurrent(Config::NETPLAY_NICKNAME, WxStrToStr(m_nickname_text->GetValue())); if (m_direct_traversal->GetCurrentSelection() == DIRECT_CHOICE) - netplay_section.Set("Address", WxStrToStr(m_connect_ip_text->GetValue())); + Config::SetBaseOrCurrent(Config::NETPLAY_ADDRESS, WxStrToStr(m_connect_ip_text->GetValue())); else - netplay_section.Set("HostCode", WxStrToStr(m_connect_hashcode_text->GetValue())); + Config::SetBaseOrCurrent(Config::NETPLAY_HOST_CODE, + WxStrToStr(m_connect_hashcode_text->GetValue())); - netplay_section.Set("ConnectPort", WxStrToStr(m_connect_port_text->GetValue())); - netplay_section.Set("HostPort", WxStrToStr(m_host_port_text->GetValue())); - netplay_section.Set("ListenPort", m_traversal_listen_port_enabled->IsChecked() ? - m_traversal_listen_port->GetValue() : - 0); + Config::SetBaseOrCurrent(Config::NETPLAY_CONNECT_PORT, + static_cast(WxStrToUL(m_connect_port_text->GetValue()))); + Config::SetBaseOrCurrent(Config::NETPLAY_HOST_PORT, + static_cast(WxStrToUL(m_host_port_text->GetValue()))); + Config::SetBaseOrCurrent(Config::NETPLAY_LISTEN_PORT, + static_cast(m_traversal_listen_port_enabled->IsChecked() ? + m_traversal_listen_port->GetValue() : + 0)); #ifdef USE_UPNP - netplay_section.Set("UseUPNP", m_upnp_chk->GetValue(), false); + Config::SetBaseOrCurrent(Config::NETPLAY_USE_UPNP, m_upnp_chk->GetValue()); #endif - inifile.Save(dolphin_ini); main_frame->m_netplay_setup_frame = nullptr; } @@ -328,17 +298,12 @@ void NetPlaySetupFrame::DoHost() return; } - IniFile ini_file; - const std::string dolphin_ini = File::GetUserPath(F_DOLPHINCONFIG_IDX); - ini_file.Load(dolphin_ini); - IniFile::Section& netplay_section = *ini_file.GetOrCreateSection("NetPlay"); - NetPlayHostConfig host_config; host_config.game_name = WxStrToStr(m_game_lbox->GetStringSelection()); host_config.use_traversal = m_direct_traversal->GetCurrentSelection() == TRAVERSAL_CHOICE; host_config.player_name = WxStrToStr(m_nickname_text->GetValue()); host_config.game_list_ctrl = m_game_list; - host_config.SetDialogInfo(netplay_section, m_parent); + host_config.SetDialogInfo(m_parent); #ifdef USE_UPNP host_config.forward_port = m_upnp_chk->GetValue(); #endif @@ -355,11 +320,10 @@ void NetPlaySetupFrame::DoHost() host_config.listen_port = static_cast(listen_port); } - host_config.traversal_port = NetPlayLaunchConfig::GetTraversalPortFromIniConfig(netplay_section); - host_config.traversal_host = NetPlayLaunchConfig::GetTraversalHostFromIniConfig(netplay_section); + host_config.traversal_port = Config::Get(Config::NETPLAY_TRAVERSAL_PORT); + host_config.traversal_host = Config::Get(Config::NETPLAY_TRAVERSAL_SERVER); - netplay_section.Set("SelectedHostGame", host_config.game_name); - ini_file.Save(dolphin_ini); + Config::SetBaseOrCurrent(Config::NETPLAY_SELECTED_HOST_GAME, host_config.game_name); if (NetPlayLauncher::Host(host_config)) { @@ -374,15 +338,11 @@ void NetPlaySetupFrame::OnJoin(wxCommandEvent&) void NetPlaySetupFrame::DoJoin() { - IniFile inifile; - inifile.Load(File::GetUserPath(F_DOLPHINCONFIG_IDX)); - IniFile::Section& netplay_section = *inifile.GetOrCreateSection("NetPlay"); - NetPlayJoinConfig join_config; join_config.use_traversal = m_direct_traversal->GetCurrentSelection() == TRAVERSAL_CHOICE; join_config.player_name = WxStrToStr(m_nickname_text->GetValue()); join_config.game_list_ctrl = m_game_list; - join_config.SetDialogInfo(netplay_section, m_parent); + join_config.SetDialogInfo(m_parent); unsigned long port = 0; m_connect_port_text->GetValue().ToULong(&port); @@ -394,8 +354,8 @@ void NetPlaySetupFrame::DoJoin() else join_config.connect_host = WxStrToStr(m_connect_ip_text->GetValue()); - join_config.traversal_port = NetPlayLaunchConfig::GetTraversalPortFromIniConfig(netplay_section); - join_config.traversal_host = NetPlayLaunchConfig::GetTraversalHostFromIniConfig(netplay_section); + join_config.traversal_port = Config::Get(Config::NETPLAY_TRAVERSAL_PORT); + join_config.traversal_host = Config::Get(Config::NETPLAY_TRAVERSAL_SERVER); if (NetPlayLauncher::Join(join_config)) { @@ -405,15 +365,12 @@ void NetPlaySetupFrame::DoJoin() void NetPlaySetupFrame::OnResetTraversal(wxCommandEvent& event) { - IniFile inifile; - const std::string dolphin_ini = File::GetUserPath(F_DOLPHINCONFIG_IDX); - inifile.Load(dolphin_ini); - IniFile::Section& netplay_section = *inifile.GetOrCreateSection("NetPlay"); - netplay_section.Delete("TraversalServer"); - netplay_section.Delete("TraversalPort"); - inifile.Save(dolphin_ini); + Config::SetBaseOrCurrent(Config::NETPLAY_TRAVERSAL_SERVER, + Config::NETPLAY_TRAVERSAL_SERVER.default_value); + Config::SetBaseOrCurrent(Config::NETPLAY_TRAVERSAL_PORT, + Config::NETPLAY_TRAVERSAL_PORT.default_value); - m_traversal_lbl->SetLabelText(GetTraversalLabelText(netplay_section)); + m_traversal_lbl->SetLabelText(GetTraversalLabelText()); } void NetPlaySetupFrame::OnTraversalListenPortChanged(wxCommandEvent& event) @@ -424,9 +381,6 @@ void NetPlaySetupFrame::OnTraversalListenPortChanged(wxCommandEvent& event) void NetPlaySetupFrame::OnDirectTraversalChoice(wxCommandEvent& event) { int sel = m_direct_traversal->GetSelection(); - IniFile inifile; - inifile.Load(File::GetUserPath(F_DOLPHINCONFIG_IDX)); - IniFile::Section& netplay_section = *inifile.GetOrCreateSection("NetPlay"); if (sel == TRAVERSAL_CHOICE) { @@ -463,10 +417,7 @@ void NetPlaySetupFrame::OnDirectTraversalChoice(wxCommandEvent& event) // Client tab { m_ip_lbl->SetLabelText(_("IP Address:")); - - std::string address; - netplay_section.Get("Address", &address, "127.0.0.1"); - m_connect_ip_text->SetLabelText(address); + m_connect_ip_text->SetLabelText(Config::Get(Config::NETPLAY_ADDRESS)); m_client_port_lbl->Show(); m_connect_port_text->Show(); diff --git a/Source/Core/DolphinWX/NetPlay/NetWindow.cpp b/Source/Core/DolphinWX/NetPlay/NetWindow.cpp index 98aefef953..870851dee1 100644 --- a/Source/Core/DolphinWX/NetPlay/NetWindow.cpp +++ b/Source/Core/DolphinWX/NetPlay/NetWindow.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -33,7 +34,6 @@ #include "Common/CommonTypes.h" #include "Common/FifoQueue.h" #include "Common/FileUtil.h" -#include "Common/IniFile.h" #include "Common/MsgHandler.h" #include "Common/StringUtil.h" @@ -77,15 +77,11 @@ NetPlayDialog::NetPlayDialog(wxWindow* const parent, const GameListCtrl* const g // Remember the window size and position for NetWindow { - IniFile inifile; - inifile.Load(File::GetUserPath(F_DOLPHINCONFIG_IDX)); - IniFile::Section& netplay_section = *inifile.GetOrCreateSection("NetPlay"); - int winPosX, winPosY, winWidth, winHeight; - netplay_section.Get("NetWindowPosX", &winPosX, std::numeric_limits::min()); - netplay_section.Get("NetWindowPosY", &winPosY, std::numeric_limits::min()); - netplay_section.Get("NetWindowWidth", &winWidth, -1); - netplay_section.Get("NetWindowHeight", &winHeight, -1); + wxConfig::Get()->Read("NetWindowPosX", &winPosX, std::numeric_limits::min()); + wxConfig::Get()->Read("NetWindowPosY", &winPosY, std::numeric_limits::min()); + wxConfig::Get()->Read("NetWindowWidth", &winWidth, -1); + wxConfig::Get()->Read("NetWindowHeight", &winHeight, -1); WxUtils::SetWindowSizeAndFitToScreen(this, wxPoint(winPosX, winPosY), wxSize(winWidth, winHeight), GetSize()); @@ -282,17 +278,10 @@ wxSizer* NetPlayDialog::CreateBottomGUI(wxWindow* parent) NetPlayDialog::~NetPlayDialog() { - IniFile inifile; - const std::string dolphin_ini = File::GetUserPath(F_DOLPHINCONFIG_IDX); - inifile.Load(dolphin_ini); - IniFile::Section& netplay_config = *inifile.GetOrCreateSection("NetPlay"); - - netplay_config.Set("NetWindowPosX", GetPosition().x); - netplay_config.Set("NetWindowPosY", GetPosition().y); - netplay_config.Set("NetWindowWidth", GetSize().GetWidth()); - netplay_config.Set("NetWindowHeight", GetSize().GetHeight()); - - inifile.Save(dolphin_ini); + wxConfig::Get()->Write("NetWindowPosX", GetPosition().x); + wxConfig::Get()->Write("NetWindowPosY", GetPosition().y); + wxConfig::Get()->Write("NetWindowWidth", GetSize().GetWidth()); + wxConfig::Get()->Write("NetWindowHeight", GetSize().GetHeight()); if (netplay_client) { diff --git a/Source/Core/DolphinWX/WxUtils.cpp b/Source/Core/DolphinWX/WxUtils.cpp index ef22a09d43..703518da3f 100644 --- a/Source/Core/DolphinWX/WxUtils.cpp +++ b/Source/Core/DolphinWX/WxUtils.cpp @@ -531,3 +531,10 @@ wxString StrToWxStr(const std::string& str) // return wxString::FromUTF8Unchecked(str.c_str()); return wxString::FromUTF8(str.c_str()); } + +unsigned long WxStrToUL(const wxString& str) +{ + unsigned long value = 0; + str.ToULong(&value); + return value; +} diff --git a/Source/Core/DolphinWX/WxUtils.h b/Source/Core/DolphinWX/WxUtils.h index 6cb449ae2d..7dc5051751 100644 --- a/Source/Core/DolphinWX/WxUtils.h +++ b/Source/Core/DolphinWX/WxUtils.h @@ -145,3 +145,4 @@ wxImage ScaleImage(wxImage image, double source_scale_factor = 1.0, std::string WxStrToStr(const wxString& str); wxString StrToWxStr(const std::string& str); +unsigned long WxStrToUL(const wxString& str);