Don't read/store settings directly from/to SYSCONF

Instead of directly reading/storing settings from/to the SYSCONF, we
now store Wii settings to Dolphin's own configuration, and apply them
on boot. This prevents issues with settings not being saved, being
overridden and lost (if the user opens a dialog that writes to the
SYSCONF while a game is running).

This also fixes restoring settings from the config cache after a
graceful shutdown; for some reason, settings were only restored
after a normal shutdown.

Fixes issue 9825 and 9826
This commit is contained in:
Léo Lam
2016-10-07 21:57:07 +02:00
parent 39fd6dcd5b
commit afd2f58e29
17 changed files with 175 additions and 129 deletions

View File

@ -10,7 +10,10 @@
#include "Common/CommonPaths.h"
#include "Common/CommonTypes.h"
#include "Common/FileUtil.h"
#include "Common/Logging/Log.h"
#include "Common/MsgHandler.h"
#include "Common/StringUtil.h"
#include "Common/SysConf.h"
#include "Core/Boot/Boot.h"
#include "Core/Boot/Boot_DOL.h"
@ -18,6 +21,7 @@
#include "Core/Core.h" // for bWii
#include "Core/FifoPlayer/FifoDataFile.h"
#include "Core/HW/SI.h"
#include "Core/IPC_HLE/WII_IPC_HLE_Device_usb_bt_base.h"
#include "Core/PowerPC/PowerPC.h"
#include "DiscIO/Enums.h"
@ -25,6 +29,39 @@
#include "DiscIO/Volume.h"
#include "DiscIO/VolumeCreator.h"
// Change from IPL.LNG value to IPL.SADR country code.
// http://wiibrew.org/wiki/Country_Codes
static u8 GetSADRCountryCode(DiscIO::Language language)
{
switch (language)
{
case DiscIO::Language::LANGUAGE_JAPANESE:
return 1; // Japan
case DiscIO::Language::LANGUAGE_ENGLISH:
return 49; // USA
case DiscIO::Language::LANGUAGE_GERMAN:
return 78; // Germany
case DiscIO::Language::LANGUAGE_FRENCH:
return 77; // France
case DiscIO::Language::LANGUAGE_SPANISH:
return 105; // Spain
case DiscIO::Language::LANGUAGE_ITALIAN:
return 83; // Italy
case DiscIO::Language::LANGUAGE_DUTCH:
return 94; // Netherlands
case DiscIO::Language::LANGUAGE_SIMPLIFIED_CHINESE:
case DiscIO::Language::LANGUAGE_TRADITIONAL_CHINESE:
return 157; // China
case DiscIO::Language::LANGUAGE_KOREAN:
return 136; // Korea
case DiscIO::Language::LANGUAGE_UNKNOWN:
break;
}
PanicAlert("Invalid language. Defaulting to Japanese.");
return 1;
}
SConfig* SConfig::m_Instance;
SConfig::SConfig()
@ -32,6 +69,7 @@ SConfig::SConfig()
LoadDefaults();
// Make sure we have log manager
LoadSettings();
LoadSettingsFromSysconf();
}
void SConfig::Init()
@ -48,7 +86,6 @@ void SConfig::Shutdown()
SConfig::~SConfig()
{
SaveSettings();
delete m_SYSCONF;
}
void SConfig::SaveSettings()
@ -56,7 +93,6 @@ void SConfig::SaveSettings()
NOTICE_LOG(BOOT, "Saving settings to %s", File::GetUserPath(F_DOLPHINCONFIG_IDX).c_str());
IniFile ini;
ini.Load(File::GetUserPath(F_DOLPHINCONFIG_IDX)); // load first to not kill unknown stuff
m_SYSCONF->Reload();
SaveGeneralSettings(ini);
SaveInterfaceSettings(ini);
@ -70,9 +106,9 @@ void SConfig::SaveSettings()
SaveAnalyticsSettings(ini);
SaveNetworkSettings(ini);
SaveBluetoothPassthroughSettings(ini);
SaveSysconfSettings(ini);
ini.Save(File::GetUserPath(F_DOLPHINCONFIG_IDX));
m_SYSCONF->Save();
}
namespace
@ -334,6 +370,47 @@ void SConfig::SaveBluetoothPassthroughSettings(IniFile& ini)
section->Set("LinkKeys", m_bt_passthrough_link_keys);
}
void SConfig::SaveSysconfSettings(IniFile& ini)
{
IniFile::Section* section = ini.GetOrCreateSection("Sysconf");
section->Set("SensorBarPosition", m_sensor_bar_position);
section->Set("SensorBarSensitivity", m_sensor_bar_sensitivity);
section->Set("SpeakerVolume", m_speaker_volume);
section->Set("WiimoteMotor", m_wiimote_motor);
section->Set("WiiLanguage", m_wii_language);
section->Set("AspectRatio", m_wii_aspect_ratio);
section->Set("Screensaver", m_wii_screensaver);
}
void SConfig::SaveSettingsToSysconf()
{
SysConf sysconf;
sysconf.SetData<u8>("IPL.SSV", m_wii_screensaver);
sysconf.SetData<u8>("IPL.LNG", m_wii_language);
u8 country_code = GetSADRCountryCode(static_cast<DiscIO::Language>(m_wii_language));
sysconf.SetArrayData("IPL.SADR", &country_code, 1);
sysconf.SetData<u8>("IPL.AR", m_wii_aspect_ratio);
sysconf.SetData<u8>("BT.BAR", m_sensor_bar_position);
sysconf.SetData<u32>("BT.SENS", m_sensor_bar_sensitivity);
sysconf.SetData<u8>("BT.SPKV", m_speaker_volume);
sysconf.SetData("BT.MOT", m_wiimote_motor);
sysconf.SetData("IPL.PGS", bProgressive);
sysconf.SetData("IPL.E60", bPAL60);
// Disable WiiConnect24's standby mode. If it is enabled, it prevents us from receiving
// shutdown commands in the State Transition Manager (STM).
// TODO: remove this if and once Dolphin supports WC24 standby mode.
sysconf.SetData<u8>("IPL.IDL", 0x00);
NOTICE_LOG(COMMON, "Disabling WC24 'standby' (shutdown to idle) to avoid hanging on shutdown");
RestoreBTInfoSection(&sysconf);
sysconf.Save();
}
void SConfig::LoadSettings()
{
INFO_LOG(BOOT, "Loading Settings from %s", File::GetUserPath(F_DOLPHINCONFIG_IDX).c_str());
@ -352,8 +429,7 @@ void SConfig::LoadSettings()
LoadNetworkSettings(ini);
LoadAnalyticsSettings(ini);
LoadBluetoothPassthroughSettings(ini);
m_SYSCONF = new SysConf();
LoadSysconfSettings(ini);
}
void SConfig::LoadGeneralSettings(IniFile& ini)
@ -626,6 +702,34 @@ void SConfig::LoadBluetoothPassthroughSettings(IniFile& ini)
section->Get("LinkKeys", &m_bt_passthrough_link_keys, "");
}
void SConfig::LoadSysconfSettings(IniFile& ini)
{
IniFile::Section* section = ini.GetOrCreateSection("Sysconf");
section->Get("SensorBarPosition", &m_sensor_bar_position, m_sensor_bar_position);
section->Get("SensorBarSensitivity", &m_sensor_bar_sensitivity, m_sensor_bar_sensitivity);
section->Get("SpeakerVolume", &m_speaker_volume, m_speaker_volume);
section->Get("WiimoteMotor", &m_wiimote_motor, m_wiimote_motor);
section->Get("WiiLanguage", &m_wii_language, m_wii_language);
section->Get("AspectRatio", &m_wii_aspect_ratio, m_wii_aspect_ratio);
section->Get("Screensaver", &m_wii_screensaver, m_wii_screensaver);
}
void SConfig::LoadSettingsFromSysconf()
{
SysConf sysconf;
m_wii_screensaver = sysconf.GetData<u8>("IPL.SSV");
m_wii_language = sysconf.GetData<u8>("IPL.LNG");
m_wii_aspect_ratio = sysconf.GetData<u8>("IPL.AR");
m_sensor_bar_position = sysconf.GetData<u8>("BT.BAR");
m_sensor_bar_sensitivity = sysconf.GetData<u32>("BT.SENS");
m_speaker_volume = sysconf.GetData<u8>("BT.SPKV");
m_wiimote_motor = sysconf.GetData<u8>("BT.MOT") != 0;
bProgressive = sysconf.GetData<u8>("IPL.PGS") != 0;
bPAL60 = sysconf.GetData<u8>("IPL.E60") != 0;
}
void SConfig::LoadDefaults()
{
bEnableDebugging = false;
@ -966,7 +1070,7 @@ DiscIO::Language SConfig::GetCurrentLanguage(bool wii) const
{
int language_value;
if (wii)
language_value = SConfig::GetInstance().m_SYSCONF->GetData<u8>("IPL.LNG");
language_value = SConfig::GetInstance().m_wii_language;
else
language_value = SConfig::GetInstance().SelectedLanguage + 1;
DiscIO::Language language = static_cast<DiscIO::Language>(language_value);