diff options
| author | Léo Lam <leo@innovatetechnologi.es> | 2019-07-21 15:32:52 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-07-21 15:32:52 +0800 |
| commit | da1fbbc5d5d0eda5fcdccadd20207b4b525f8a7e (patch) | |
| tree | 28afb7bb2892547e824f688261ec50c0616ef15b /Source/Core/DiscIO/Volume.cpp | |
| parent | cd7a374ab91f1f1dd46e5631309bea7ed5efc23d (diff) | |
| parent | 34f32898e63e7dd5d0251fd630f8d569432c9ac3 (diff) | |
Merge pull request #8243 from JosJuice/merge-wad-classes
DiscIO: Merge WiiWAD into VolumeWAD
Diffstat (limited to 'Source/Core/DiscIO/Volume.cpp')
| -rw-r--r-- | Source/Core/DiscIO/Volume.cpp | 51 |
1 files changed, 41 insertions, 10 deletions
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<Language, std::string> Volume::ReadWiiNames(const std::vector<char16_t> return names; } -std::unique_ptr<Volume> CreateVolumeFromFilename(const std::string& filename) +static std::unique_ptr<VolumeDisc> CreateDisc(std::unique_ptr<BlobReader>& reader) { - std::unique_ptr<BlobReader> reader(CreateBlobReader(filename)); - if (reader == nullptr) - return nullptr; - // Check for Wii const std::optional<u32> wii_magic = reader->ReadSwapped<u32>(0x18); if (wii_magic == u32(0x5D1C9EA3)) return std::make_unique<VolumeWii>(std::move(reader)); + // Check for GC + const std::optional<u32> gc_magic = reader->ReadSwapped<u32>(0x1C); + if (gc_magic == u32(0xC2339F3D)) + return std::make_unique<VolumeGC>(std::move(reader)); + + // No known magic words found + return nullptr; +} + +std::unique_ptr<VolumeDisc> CreateDisc(const std::string& path) +{ + std::unique_ptr<BlobReader> reader(CreateBlobReader(path)); + return reader ? CreateDisc(reader) : nullptr; +} + +static std::unique_ptr<VolumeWAD> CreateWAD(std::unique_ptr<BlobReader>& reader) +{ // Check for WAD // 0x206962 for boot2 wads const std::optional<u32> wad_magic = reader->ReadSwapped<u32>(0x02); if (wad_magic == u32(0x00204973) || wad_magic == u32(0x00206962)) return std::make_unique<VolumeWAD>(std::move(reader)); - // Check for GC - const std::optional<u32> gc_magic = reader->ReadSwapped<u32>(0x1C); - if (gc_magic == u32(0xC2339F3D)) - return std::make_unique<VolumeGC>(std::move(reader)); - // No known magic words found return nullptr; } +std::unique_ptr<VolumeWAD> CreateWAD(const std::string& path) +{ + std::unique_ptr<BlobReader> reader(CreateBlobReader(path)); + return reader ? CreateWAD(reader) : nullptr; +} + +std::unique_ptr<Volume> CreateVolume(const std::string& path) +{ + std::unique_ptr<BlobReader> reader(CreateBlobReader(path)); + if (reader == nullptr) + return nullptr; + + std::unique_ptr<VolumeDisc> disc = CreateDisc(reader); + if (disc) + return disc; + + std::unique_ptr<VolumeWAD> wad = CreateWAD(reader); + if (wad) + return wad; + + return nullptr; +} + } // namespace DiscIO |
