ConfigManager: Refactor setting the region into a new function

This commit is contained in:
JosJuice 2017-01-25 14:42:11 +01:00
parent 8475b03bd8
commit 188d36ff26
2 changed files with 21 additions and 29 deletions

View File

@ -789,6 +789,17 @@ const char* SConfig::GetDirectoryForRegion(DiscIO::Region region)
} }
} }
// Sets m_region to the region parameter, or to PAL if the region parameter
// is invalid. Set directory_name to the value returned by GetDirectoryForRegion
// for m_region. Returns false if the region parameter is invalid.
bool SConfig::SetRegion(DiscIO::Region region, std::string* directory_name)
{
const char* retrieved_region_dir = GetDirectoryForRegion(region);
m_region = retrieved_region_dir ? region : DiscIO::Region::PAL;
*directory_name = retrieved_region_dir ? retrieved_region_dir : EUR_DIR;
return !!retrieved_region_dir;
}
bool SConfig::AutoSetup(EBootBS2 _BootBS2) bool SConfig::AutoSetup(EBootBS2 _BootBS2)
{ {
std::string set_region_dir(EUR_DIR); std::string set_region_dir(EUR_DIR);
@ -835,18 +846,10 @@ bool SConfig::AutoSetup(EBootBS2 _BootBS2)
// Check if we have a Wii disc // Check if we have a Wii disc
bWii = pVolume->GetVolumeType() == DiscIO::Platform::WII_DISC; bWii = pVolume->GetVolumeType() == DiscIO::Platform::WII_DISC;
m_region = pVolume->GetRegion(); if (!SetRegion(pVolume->GetRegion(), &set_region_dir))
const char* retrieved_region_dir = GetDirectoryForRegion(m_region);
if (!retrieved_region_dir)
{
if (!PanicYesNoT("Your GCM/ISO file seems to be invalid (invalid country)." if (!PanicYesNoT("Your GCM/ISO file seems to be invalid (invalid country)."
"\nContinue with PAL region?")) "\nContinue with PAL region?"))
return false; return false;
m_region = DiscIO::Region::PAL;
retrieved_region_dir = EUR_DIR;
}
set_region_dir = retrieved_region_dir;
} }
else if (!strcasecmp(Extension.c_str(), ".elf")) else if (!strcasecmp(Extension.c_str(), ".elf"))
{ {
@ -856,8 +859,7 @@ bool SConfig::AutoSetup(EBootBS2 _BootBS2)
// all GC homebrew to 50Hz. // all GC homebrew to 50Hz.
// In the future, it probably makes sense to add a Region setting for homebrew somewhere in // In the future, it probably makes sense to add a Region setting for homebrew somewhere in
// the emulator config. // the emulator config.
m_region = bWii ? DiscIO::Region::PAL : DiscIO::Region::NTSC_U; SetRegion(bWii ? DiscIO::Region::PAL : DiscIO::Region::NTSC_U, &set_region_dir);
set_region_dir = bWii ? EUR_DIR : USA_DIR;
m_BootType = BOOT_ELF; m_BootType = BOOT_ELF;
} }
else if (!strcasecmp(Extension.c_str(), ".dol")) else if (!strcasecmp(Extension.c_str(), ".dol"))
@ -865,15 +867,13 @@ bool SConfig::AutoSetup(EBootBS2 _BootBS2)
CDolLoader dolfile(m_strFilename); CDolLoader dolfile(m_strFilename);
bWii = dolfile.IsWii(); bWii = dolfile.IsWii();
// TODO: See the ELF code above. // TODO: See the ELF code above.
m_region = bWii ? DiscIO::Region::PAL : DiscIO::Region::NTSC_U; SetRegion(bWii ? DiscIO::Region::PAL : DiscIO::Region::NTSC_U, &set_region_dir);
set_region_dir = bWii ? EUR_DIR : USA_DIR;
m_BootType = BOOT_DOL; m_BootType = BOOT_DOL;
} }
else if (!strcasecmp(Extension.c_str(), ".dff")) else if (!strcasecmp(Extension.c_str(), ".dff"))
{ {
bWii = true; bWii = true;
m_region = DiscIO::Region::NTSC_U; SetRegion(DiscIO::Region::NTSC_U, &set_region_dir);
set_region_dir = USA_DIR;
m_BootType = BOOT_DFF; m_BootType = BOOT_DFF;
std::unique_ptr<FifoDataFile> ddfFile(FifoDataFile::Load(m_strFilename, true)); std::unique_ptr<FifoDataFile> ddfFile(FifoDataFile::Load(m_strFilename, true));
@ -898,14 +898,7 @@ bool SConfig::AutoSetup(EBootBS2 _BootBS2)
return false; // do not boot return false; // do not boot
} }
m_region = ContentLoader.GetRegion(); SetRegion(ContentLoader.GetRegion(), &set_region_dir);
const char* retrieved_region_dir = GetDirectoryForRegion(m_region);
if (!retrieved_region_dir)
{
m_region = DiscIO::Region::PAL;
retrieved_region_dir = EUR_DIR;
}
set_region_dir = retrieved_region_dir;
bWii = true; bWii = true;
m_BootType = BOOT_WII_NAND; m_BootType = BOOT_WII_NAND;
@ -946,20 +939,17 @@ bool SConfig::AutoSetup(EBootBS2 _BootBS2)
break; break;
case BOOT_BS2_USA: case BOOT_BS2_USA:
m_region = DiscIO::Region::NTSC_U; SetRegion(DiscIO::Region::NTSC_U, &set_region_dir);
set_region_dir = USA_DIR;
m_strFilename.clear(); m_strFilename.clear();
break; break;
case BOOT_BS2_JAP: case BOOT_BS2_JAP:
m_region = DiscIO::Region::NTSC_J; SetRegion(DiscIO::Region::NTSC_J, &set_region_dir);
set_region_dir = JAP_DIR;
m_strFilename.clear(); m_strFilename.clear();
break; break;
case BOOT_BS2_EUR: case BOOT_BS2_EUR:
m_region = DiscIO::Region::PAL; SetRegion(DiscIO::Region::PAL, &set_region_dir);
set_region_dir = EUR_DIR;
m_strFilename.clear(); m_strFilename.clear();
break; break;
} }

View File

@ -365,5 +365,7 @@ private:
void LoadBluetoothPassthroughSettings(IniFile& ini); void LoadBluetoothPassthroughSettings(IniFile& ini);
void LoadSysconfSettings(IniFile& ini); void LoadSysconfSettings(IniFile& ini);
bool SetRegion(DiscIO::Region region, std::string* directory_name);
static SConfig* m_Instance; static SConfig* m_Instance;
}; };