DiscIO: Simplify volume creation

Basically inlining GetDiscType into CreateVolumeFromFilename.
This commit is contained in:
JosJuice 2017-05-19 18:18:43 +02:00
parent 643b218c1d
commit 56b218a750
1 changed files with 21 additions and 54 deletions

View File

@ -22,39 +22,37 @@
namespace DiscIO
{
enum EDiscType
{
DISC_TYPE_UNK,
DISC_TYPE_WII,
DISC_TYPE_WII_CONTAINER,
DISC_TYPE_GC,
DISC_TYPE_WAD
};
EDiscType GetDiscType(IBlobReader& _rReader);
std::unique_ptr<IVolume> CreateVolumeFromFilename(const std::string& filename)
{
std::unique_ptr<IBlobReader> reader(CreateBlobReader(filename));
if (reader == nullptr)
return nullptr;
CBlobBigEndianReader be_reader(*reader);
switch (GetDiscType(*reader))
{
case DISC_TYPE_WII:
case DISC_TYPE_GC:
// Check for Wii
u32 wii_magic = 0;
be_reader.ReadSwapped(0x18, &wii_magic);
u32 wii_container_magic = 0;
be_reader.ReadSwapped(0x60, &wii_container_magic);
if (wii_magic == 0x5D1C9EA3 && wii_container_magic != 0)
return std::make_unique<CVolumeGC>(std::move(reader));
case DISC_TYPE_WAD:
return std::make_unique<CVolumeWAD>(std::move(reader));
case DISC_TYPE_WII_CONTAINER:
if (wii_magic == 0x5D1C9EA3 && wii_container_magic == 0)
return std::make_unique<CVolumeWiiCrypted>(std::move(reader));
case DISC_TYPE_UNK:
return nullptr;
}
// Check for WAD
// 0x206962 for boot2 wads
u32 wad_magic = 0;
be_reader.ReadSwapped(0x02, &wad_magic);
if (wad_magic == 0x00204973 || wad_magic == 0x00206962)
return std::make_unique<CVolumeWAD>(std::move(reader));
// Check for GC
u32 gc_magic = 0;
be_reader.ReadSwapped(0x1C, &gc_magic);
if (gc_magic == 0xC2339F3D)
return std::make_unique<CVolumeGC>(std::move(reader));
// No known magic words found
return nullptr;
}
@ -68,35 +66,4 @@ std::unique_ptr<IVolume> CreateVolumeFromDirectory(const std::string& directory,
return nullptr;
}
EDiscType GetDiscType(IBlobReader& _rReader)
{
CBlobBigEndianReader Reader(_rReader);
// Check for Wii
u32 WiiMagic = 0;
Reader.ReadSwapped(0x18, &WiiMagic);
u32 WiiContainerMagic = 0;
Reader.ReadSwapped(0x60, &WiiContainerMagic);
if (WiiMagic == 0x5D1C9EA3 && WiiContainerMagic != 0)
return DISC_TYPE_WII;
if (WiiMagic == 0x5D1C9EA3 && WiiContainerMagic == 0)
return DISC_TYPE_WII_CONTAINER;
// Check for WAD
// 0x206962 for boot2 wads
u32 WADMagic = 0;
Reader.ReadSwapped(0x02, &WADMagic);
if (WADMagic == 0x00204973 || WADMagic == 0x00206962)
return DISC_TYPE_WAD;
// Check for GC
u32 GCMagic = 0;
Reader.ReadSwapped(0x1C, &GCMagic);
if (GCMagic == 0xC2339F3D)
return DISC_TYPE_GC;
// No known magic words found
return DISC_TYPE_UNK;
}
} // namespace