diff options
| author | JosJuice <josjuice@gmail.com> | 2017-05-19 18:33:21 +0200 |
|---|---|---|
| committer | JosJuice <josjuice@gmail.com> | 2017-05-19 18:33:21 +0200 |
| commit | ac5c82b36b4fc2bf99e9f7552ac83febeff8fc5c (patch) | |
| tree | 074dc847a2c34aaf089b4d0103be34b8712dd3c2 /Source/Core/DiscIO/Volume.cpp | |
| parent | 56b218a7505d11b72dec1d5b36e948f77950331a (diff) | |
DiscIO: Remove VolumeCreator
This file is pretty small now that it doesn't handle Wii
partitions anymore, so let's move its contents to Volume.cpp.
This is also more consistent with how blob creation works.
Diffstat (limited to 'Source/Core/DiscIO/Volume.cpp')
| -rw-r--r-- | Source/Core/DiscIO/Volume.cpp | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/Source/Core/DiscIO/Volume.cpp b/Source/Core/DiscIO/Volume.cpp index ade2bd1eab..21fece4484 100644 --- a/Source/Core/DiscIO/Volume.cpp +++ b/Source/Core/DiscIO/Volume.cpp @@ -6,6 +6,7 @@ #include <algorithm> #include <map> +#include <memory> #include <string> #include <utility> #include <vector> @@ -17,7 +18,12 @@ #include "Common/StringUtil.h" #include "Common/Swap.h" +#include "DiscIO/Blob.h" #include "DiscIO/Enums.h" +#include "DiscIO/VolumeDirectory.h" +#include "DiscIO/VolumeGC.h" +#include "DiscIO/VolumeWad.h" +#include "DiscIO/VolumeWiiCrypted.h" namespace DiscIO { @@ -76,4 +82,49 @@ std::map<Language, std::string> IVolume::ReadWiiNames(const std::vector<u8>& dat } return names; } + +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); + + // 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)); + if (wii_magic == 0x5D1C9EA3 && wii_container_magic == 0) + return std::make_unique<CVolumeWiiCrypted>(std::move(reader)); + + // 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; } + +std::unique_ptr<IVolume> CreateVolumeFromDirectory(const std::string& directory, bool is_wii, + const std::string& apploader, + const std::string& dol) +{ + if (CVolumeDirectory::IsValidDirectory(directory)) + return std::make_unique<CVolumeDirectory>(directory, is_wii, apploader, dol); + + return nullptr; +} + +} // namespace |
