From 0f5a4b37ee8e00210b211953969f10bfb48c5aaa Mon Sep 17 00:00:00 2001 From: JosJuice Date: Sun, 14 Jul 2019 15:49:42 +0200 Subject: DiscIO: Add functions CreateDisc and CreateWAD ...in addition to the existing function CreateVolume (renamed from CreateVolumeFromFilename). Lets code easily add constraints such as not letting the user select a WAD file when using the disc changing functionality. --- Source/Core/DiscIO/Volume.cpp | 51 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 41 insertions(+), 10 deletions(-) (limited to 'Source/Core/DiscIO/Volume.cpp') diff --git a/Source/Core/DiscIO/Volume.cpp b/Source/Core/DiscIO/Volume.cpp index e699e46a93..e1f1bbae4e 100644 --- a/Source/Core/DiscIO/Volume.cpp +++ b/Source/Core/DiscIO/Volume.cpp @@ -43,30 +43,61 @@ std::map Volume::ReadWiiNames(const std::vector return names; } -std::unique_ptr CreateVolumeFromFilename(const std::string& filename) +static std::unique_ptr CreateDisc(std::unique_ptr& reader) { - std::unique_ptr reader(CreateBlobReader(filename)); - if (reader == nullptr) - return nullptr; - // Check for Wii const std::optional wii_magic = reader->ReadSwapped(0x18); if (wii_magic == u32(0x5D1C9EA3)) return std::make_unique(std::move(reader)); + // Check for GC + const std::optional gc_magic = reader->ReadSwapped(0x1C); + if (gc_magic == u32(0xC2339F3D)) + return std::make_unique(std::move(reader)); + + // No known magic words found + return nullptr; +} + +std::unique_ptr CreateDisc(const std::string& path) +{ + std::unique_ptr reader(CreateBlobReader(path)); + return reader ? CreateDisc(reader) : nullptr; +} + +static std::unique_ptr CreateWAD(std::unique_ptr& reader) +{ // Check for WAD // 0x206962 for boot2 wads const std::optional wad_magic = reader->ReadSwapped(0x02); if (wad_magic == u32(0x00204973) || wad_magic == u32(0x00206962)) return std::make_unique(std::move(reader)); - // Check for GC - const std::optional gc_magic = reader->ReadSwapped(0x1C); - if (gc_magic == u32(0xC2339F3D)) - return std::make_unique(std::move(reader)); - // No known magic words found return nullptr; } +std::unique_ptr CreateWAD(const std::string& path) +{ + std::unique_ptr reader(CreateBlobReader(path)); + return reader ? CreateWAD(reader) : nullptr; +} + +std::unique_ptr CreateVolume(const std::string& path) +{ + std::unique_ptr reader(CreateBlobReader(path)); + if (reader == nullptr) + return nullptr; + + std::unique_ptr disc = CreateDisc(reader); + if (disc) + return disc; + + std::unique_ptr wad = CreateWAD(reader); + if (wad) + return wad; + + return nullptr; +} + } // namespace DiscIO -- cgit v1.2.3