Boot: Clean up the boot code

* Move out boot parameters to a separate struct, which is not part
  of SConfig/ConfigManager because there is no reason for it to
  be there.

* Move out file name parsing and constructing the appropriate params
  from paths to a separate function that does that, and only that.

* For every different boot type we support, add a proper struct with
  only the required parameters, with descriptive names and use
  std::variant to only store what we need.

* Clean up the bHLE_BS2 stuff which made no sense sometimes. Now
  instead of using bHLE_BS2 for two different things, both for storing
  the user config setting and as a runtime boot parameter,
  we simply replace the Disc boot params with BootParameters::IPL.

* Const correctness so it's clear what can or cannot update the config.

* Drop unused parameters and unneeded checks.

* Make a few checks a lot more concise. (Looking at you, extension
  checks for disc images.)

* Remove a mildly terrible workaround where we needed to pass an empty
  string in order to boot the GC IPL without any game inserted.
  (Not required anymore thanks to std::variant and std::optional.)

The motivation for this are multiple: cleaning up and being able to add
support for booting an installed NAND title. Without this change, it'd
be pretty much impossible to implement that.

Also, using std::visit with std::variant makes the compiler do
additional type checks: now we're guaranteed that the boot code will
handle all boot types and no invalid boot type will be possible.
This commit is contained in:
Léo Lam
2017-05-27 15:43:40 +02:00
parent 4d2fb9b9ba
commit 22992ae41e
18 changed files with 468 additions and 440 deletions

View File

@ -51,6 +51,8 @@ enum GPUDeterminismMode
GPU_DETERMINISM_FAKE_COMPLETION,
};
struct BootParameters;
struct SConfig : NonCopyable
{
// Wii Devices
@ -182,25 +184,6 @@ struct SConfig : NonCopyable
bool bEnableCustomRTC;
u32 m_customRTCValue;
enum EBootBS2
{
BOOT_DEFAULT,
BOOT_BS2_JAP,
BOOT_BS2_USA,
BOOT_BS2_EUR,
};
enum EBootType
{
BOOT_ISO,
BOOT_ELF,
BOOT_DOL,
BOOT_WII_NAND,
BOOT_BS2,
BOOT_DFF
};
EBootType m_BootType;
DiscIO::Region m_region;
std::string m_strVideoBackend;
@ -210,7 +193,6 @@ struct SConfig : NonCopyable
GPUDeterminismMode m_GPUDeterminismMode;
// files
std::string m_strFilename;
std::string m_strBootROM;
std::string m_strSRAM;
std::string m_strDefaultISO;
@ -220,6 +202,9 @@ struct SConfig : NonCopyable
std::string m_perfDir;
// TODO: remove this as soon as the ticket view hack in IOS/ES/Views is dropped.
bool m_disc_booted_from_game_list = false;
const std::string& GetGameID() const { return m_game_id; }
const std::string& GetTitleDescription() const { return m_title_description; }
u64 GetTitleID() const { return m_title_id; }
@ -231,7 +216,7 @@ struct SConfig : NonCopyable
void LoadDefaults();
static const char* GetDirectoryForRegion(DiscIO::Region region);
std::string GetBootROMPath(const std::string& region_directory) const;
bool AutoSetup(EBootBS2 _BootBS2);
bool SetPathsAndGameMetadata(const BootParameters& boot);
void CheckMemcardPath(std::string& memcardPath, const std::string& gameRegion, bool isSlotA);
DiscIO::Language GetCurrentLanguage(bool wii) const;
@ -389,7 +374,6 @@ private:
void SetRunningGameMetadata(const std::string& game_id, u64 title_id, u16 revision,
Core::TitleDatabase::TitleType type);
bool SetRegion(DiscIO::Region region, std::string* directory_name);
static SConfig* m_Instance;